How can I find the value with the most change in my histogram?

[N,edges] = histcounts(Y);
min = mean();
[k1,k2,k3]=size(imYuv) %Size of the picture
for i=1:k1
for j=1:k2
if Y(i,j)>min
Y(i,j)=0;
end
end
end
imYuv(:,:,1)=Y;
final = colorspace('RGB<-YUV',imYuv);
HIstogram1.jpg
I know the value is around .64 something.
But im trying to automated so it can select that for my threshold value.

4 Comments

What do you know about your image and how much control do you have over the image capture conditions? Would it be alright to just find the min value between 0.5 and 0.7, or would that not work. If it would not work, why not? Attach an image where it would not work.
I am supposed to just have my image, and find a luminance threshold and omit the data that is pass .67. The only reason I would know that the value is between 0.5 and 0.7 is because you can see it and pin point it. But looking at larger data or set of images with different type of luminance and different changing points, it would be too tedious to go through each and every individual image to do that.
I don't understand. Do you just want to blacken any values higher than 0.67? Or is it variable? Because you have lots of minimums all over the place. If it's variable then how are we supposed to know to take the min between 0.5 and 0.7 and not the min between 0.5 and 0.35, or any other min?
Yeah I want to just blacken the values greater than 0.67, and use that to make all the values greater than that black. What my professor told me was to, get the minimun next to the largest or the one with the biggest change . That is how you would know to use that minimum instead of the others.

Answers (1)

More detail with example:
data=[1 2 -4 5 6 0 5 20 10]; % Hist data is just simillar array
diff_data=diff(data)
idx=find(diff_data==max(diff_data));
threshold=data(idx+1)

2 Comments

Should I use the N or the edges or would it work with both?
You can get it just see the maximum different (with neighbours) in number of pixels (N).

This question is closed.

Products

Release

R2019b

Asked:

on 13 Oct 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!