Finding minimum and maximum value in a histogram
이전 댓글 표시
I have an image of a face with all its non-skin part removed (hair, shirt, eyebrow, etc). From that image, I want to find its minimum and maximum value in its histogram of X and Y channel (CIE XYZ). I've tried sorting value from left side to middle and right side to middle, but the minimum value gets messed up. Anyone have an idea I can try?
Here's the code I've tried:
clc
clear all
close all
img_rgb=imread('crop02.jpg');
img_xyz=rgb2xyz(img_rgb);
img_x=img_xyz(:,:,1);
img_y=img_xyz(:,:,2);
hist_x=imhist(img_x);
hist_y=imhist(img_y);
min_x=0;
max_x=0;
min_y=0;
max_y=0;
for i=1:1:length(hist_x)
if min_x==0
if hist_x(i)~=0
min_x=i;
end
end
end
for i=length(hist_x):-1:1
if max_x==0
if hist_x(i)~=0
max_x=i;
end
end
end
for i=1:1:length(hist_y)
if min_y==0
if hist_y(i)~=0
min_y=i;
end
end
end
for i=length(hist_y):-1:1
if max_y==0
if hist_y(i)~=0
max_y=i;
end
end
end
min_x=(min_x-1)/(length(hist_x)-1)
max_x=(max_x-1)/(length(hist_x)-1)
min_y=(min_y-1)/(length(hist_y)-1)
max_y=(max_y-1)/(length(hist_y)-1)
+EDIT+ I'm trying to find minimum and maximum value of X-axis, not the Y-axis, in the area I marked. With min() and max() function, the minimum value is 0, and maximum value is about 0.7~0.9 with all three of them. As I see it, those values do not represent the area I marked. The second histogram should have min value of ~0.07 and max value of ~0.32. How should I do it?






채택된 답변
추가 답변 (1개)
Walter Roberson
2016년 4월 13일
Use the two-output versions of max() and min() . Those return indices in the second output.
[largescount, index_of_largest] = max(YourCountArray);
Now you can use index_of_largest to connect to whatever that slot in the count represents.
카테고리
도움말 센터 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!