Reputation: 25
So I created an image histogram in Matlab, and the user is able to use imrect to select a desired region.
I would like to be able to find the minimum y-value from the region that the user selects.
Here's what I have so far:
handles.pet_hist_rect = imrect(gca);
[xmin ymin width height] = getPosition(handles.pet_hist_rect);
xdata = get(findobj(gcf,'type','patch'),'xdata');
ydata = get(findobj(gcf,'type','patch'),'ydata');
I'm not sure how to extract the minimum y-value (from ydata) in the range [xmin, xmin+width]
Thanks in advance!
Upvotes: 0
Views: 71
Reputation: 1981
I think your code doesn't run in the first place, cause you are trying to assign the output of getPosition (a 1x4 array) to the single entries of another array, which doesn't work. After correcting this to
position = getPosition(handles.pet_hist_rect);
you can now access xmin as position(1), ymin as position(2) and so on. Now, ymin = position(2) is already what you are asking for (minimum of y), but I'm not sure, I'm getting you right here. There is no need to query the graphics properties. If this is not what you are looking for, you are going to have to rephrase the question a little bit.
Edit: The following is super crude, should work, does not work however, if any of the histogram counts are zero!
close all;
hist(rand(1000, 1));
handles.pet_hist_rect = imrect(gca);
position = getPosition(handles.pet_hist_rect);
xdata = get(findobj(gcf,'type','patch'),'xdata');
ydata = get(findobj(gcf,'type','patch'),'ydata');
x = xdata{1};
x(x < position(1))=0;
x(x > position(1) + position(3))=0;
x(x>0) = 1;
y = ydata{1}(logical(x));
y(y==0) = NaN;
m = min(y);
Upvotes: 1