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?

 Respuesta aceptada

Image Analyst
Image Analyst el 13 de Abr. de 2016
If you want the max and min in the image (rather than of the bin center or edge values), you can use max():
min_x = min(img_x(:));
min_y = min(img_y(:));
max_x = max(img_x(:));
max_y = max(img_y(:));

4 comentarios

Alvin Radeka
Alvin Radeka el 13 de Abr. de 2016
Same results, but much shorter, thank you. But this result is not the one I was hoping for. I will add screenshot of the histogram and the value I am trying to extract ASAP. Hope it will give clearer picture of what I was trying to do.
If you want the values from the histogram instead of the image itself, they will be quantized of course. But use the new histogram() function to return a histogram object. That object has tons of information in it
histObj = histogram(yourData);
Alvin Radeka
Alvin Radeka el 13 de Abr. de 2016
Yes, this new function will be easier to process I guess. And I've edited my question to add few pictures and short explanation. If you don't mind, please take a look at it.
Image Analyst
Image Analyst el 13 de Abr. de 2016
If you have a single pixel, it will affect the min or max. You may want to use cumsum() to take the CDF of the histogram and find the 1% and 99%, or 5% and 95% points for the x and y channels.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 13 de Abr. de 2016
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.

1 comentario

Alvin Radeka
Alvin Radeka el 13 de Abr. de 2016
I see. But still the returned value was different than what I had in mind. I will edit my question to add few screenshots. If you don't mind, please take a look at it.

Iniciar sesión para comentar.

Preguntada:

el 13 de Abr. de 2016

Comentada:

el 13 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by