getting error while executing matlab code?
1 回表示 (過去 30 日間)
古いコメントを表示
I will be using this above photo in my code . I have saved it in my computer with name "toys.jpg"
i have also attached error snaphot
My code is as below
clc;clear all;close all;
%Making matrix for 4 colors
MatrixR=[0,0,0,0,1,1,1,1];
MatrixG=[0,0,1,1,0,0,1,1];
MatrixB=[0,1,0,1,0,1,0,1];
%B,Blue,G,C,R,P,Y,W
RGBMatrix=uint8(255*((cat(3,MatrixR,MatrixG,MatrixB))));
%Converting these matrix to Gray
GrayVersion=((rgb2gray(RGBMatrix)));
%Plotting
subplot 211
imshow(RGBMatrix,[0 255]);
title('RGB matrix of toys color');
subplot 212
imshow(GrayVersion,[0 255]);
title('Grayscale mapping of RGB matrix');
%Reading ToyImage
ToyImage=uint8(imread('toys.jpg'));
%Placing Cursor
dcm_obj1 = datacursormode(figure);
imshow(ToyImage,[]);
datacursormode on
fprintf('Select the toy from the Image Displayed\n');
waitforbuttonpress;
c_info = getCursorInfo(dcm_obj1);
position=c_info.Position; %extracting position for finding toy
grayValueFromImage=double(ToyImage(position(2),position(1)));
%Formula
red=abs(double(GrayVersion(5))-grayValueFromImage); green=abs(double(GrayVersion(3))-grayValueFromImage);
blue=abs(double(GrayVersion(2))-grayValueFromImage); yellow=abs(double(GrayVersion(7))-grayValueFromImage);
%Condition
minimumAmongArray=min([red,blue,green,yellow]);
fprintf('At Position \n');
disp(position);
if(minimumAmongArray==red)
fprintf('The selected toy has Red Color\n');
end
if(minimumAmongArray==green)
fprintf('The selected toy has Green Color\n');
end
if(minimumAmongArray==blue)
fprintf('The selected toy has Blue Color\n');
end
if(minimumAmongArray==yellow)
fprintf('The selected toy has Yellow Color\n');
end
0 件のコメント
回答 (1 件)
Ameer Hamza
2020 年 5 月 16 日
The line
dcm_obj1 = datacursormode(figure);
will only return a struct if you have selected a datatip. However, in the case of your image, there is no datatip. If you are trying to find the position of last mouse click, then you can do it like this
ax = gca;
ax.CurrentPoint
5 件のコメント
Ameer Hamza
2020 年 5 月 16 日
You don't need those lines. Replace the lines of code to find the position of the cursor in your current code with the lines I suggested. Specifically delete these lines
c_info = getCursorInfo(dcm_obj1);
position=c_info.Position; %extracting position for finding toy
and replace it with
ax = gca;
cp = get(ax, 'CurrentPoint')
position = cp(1, 1:2)
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!