getting error while executing matlab code?

1 visualización (últimos 30 días)
ABTJ
ABTJ el 16 de Mayo de 2020
Comentada: ABTJ el 16 de Mayo de 2020
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

Respuestas (1)

Ameer Hamza
Ameer Hamza el 16 de Mayo de 2020
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 comentarios
Ameer Hamza
Ameer Hamza el 16 de Mayo de 2020
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 el 16 de Mayo de 2020
thank you so much dear

Iniciar sesión para comentar.

Categorías

Más información sobre Red en Help Center y File Exchange.

Productos


Versión

R2011b

Community Treasure Hunt

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

Start Hunting!

Translated by