getting error while executing matlab code?

조회 수: 1 (최근 30일)
ABTJ
ABTJ 2020년 5월 16일
댓글: ABTJ 2020년 5월 16일
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

답변 (1개)

Ameer Hamza
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
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)
ABTJ
ABTJ 2020년 5월 16일
thank you so much dear

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2011b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by