Looking at data from image using Datacursormode and ROI (drawrectangle)
Show older comments
Hi there,
I am trying to make use of datacursormode to select points/regions I am interested in and displaying the x, y, and rgb values at that point. This is the code I have used and the function to generate the position at the location I have selected. However, I can't seem to be able to generate the RGB values when I umcomment the line CData and it shows "unable to update datatip using custom update function".
figure
imagesc; axis image;
datacursormode on
dcm = datacursormode(gcf);
set(dcm,'UpdateFcn',@myupdatefcn_example)
function txt = myupdatefcn_example(trash,event)
pos = get(event,'Position');
I = get(event, 'DataIndex');
% CData = get(event,'CData');
txt = {[num2str(pos(1))],...
[num2str(pos(2))],...
[num2str(I)]};
end
Next, I would also like to draw a rectangle and extract the mean RGB values within that rectangle using the datacursormode as well so that it is interactive. I found this drawrectangle function that allows me to draw the rectangle I want on the image, and also generates the position of the box. However, I am not quite sure how to link this up with the datacursormode.
figure
imagesc; axis image;
roi = drawrectangle('Color',[1 0 0]);
addlistener(roi,'MovingROI',@allevents);
function allevents(src,evt)
evname = evt.EventName;
switch(evname)
case{'MovingROI'}
disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moving current position: ' mat2str(round(evt.CurrentPosition))]);
case{'ROIMoved'}
disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]);
end
end
Could anyone please advise? Thank you for your time.
Best Regards,
Wayne
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!