Hi Wayne,
It is my understanding that you wish to know why
CData = get(event,'CData');
affects the operation of your custom update function. This is because the CData field does not belong to the events (info) object of UpdateFcn . The image pixel values in the UpdateFcn can be accessed by passing arguments to the callback function as shown below, f = figure;
imagesc(I);
handles.I = I;
dcm = datacursormode;
dcm.Enable = 'on';
dcm.UpdateFcn = {@coordinates,handles};
function txt = coordinates(~,info,handles)
x = info.Position(1);
y = info.Position(2);
R = handles.I(x,y,1);
B = handles.I(x,y,2);
G = handles.I(x,y,3);
txt = ['(' num2str(x) ', ' num2str(y) ')'':(' num2str(R) ', ' num2str(G) ', ' num2str(B) ')'];
end
The datacursormode is only used to put up datatip in specific points in a figure or a plot. To access values from the ROI, the listener function can be used. Your ROI Listener can be modified as shown below to get the mean RGB values, function allevents(src,evt)
evname = evt.EventName;
him = findobj(src.Parent,'Type','image');
switch(evname)
case{'MovingROI'}
mask = src.createMask(him(1).CData);
[r,c] = find(mask);
P = impixel(him.CData,r,c);
RGBmean = mean(P,1)
end
end
The mean value of RGB is printed to command line for every ROI update.
Hope this Helps.
Kiran Felix Robert
Best Answer