0

I am doing a project on 'moment preserving thresholding'.. in that after doing certain operations we get certain values for p(p0,p1,p2,p3...) and the output(threshold value) is found from the histogram of the image, choosing threshold as the P0-tile.. the values of p(p0,p1,p2...) are fractions less than one(say 0.34,0.46) my problem is how can i find the value of such fraction value-tiles from the histogram..

PS:I am doing this in MAT lab

I'm new to stack overflow so i cannot post the image.. can anybody help me..

  • possible duplicate of [getting the value of the i-th tile in the input histogram in matlab](http://stackoverflow.com/questions/14929378/getting-the-value-of-the-i-th-tile-in-the-input-histogram-in-matlab) – Shai Feb 18 '13 at 08:12
  • yes the same question was posted by me..i need to know the answer as it is a part of my project...do you know how to retrieve the values @Shai – user2081934 Feb 18 '13 at 08:16

1 Answers1

0

You need to use accumulative distribution

[n x] = hist( I(:), 1000 ); % 1000 bin histogram
density = n/sum(n);
cdf     = cumsum(density); % sums to one
% Choosing a thershold such that fraction p of the pixels are below it
thri = find( cdf >= p , 1, 'first' );  % edit here from < to >=
thr = x( thri );
Shai
  • 111,146
  • 38
  • 238
  • 371
  • can you tell me why you used 1000 in the hist function...@Shai – user2081934 Feb 18 '13 at 08:27
  • @user2081934 for no reason at all. If you have any other preference (like 256) or if you know the bins' centers (`x`) you may use them. – Shai Feb 18 '13 at 08:32
  • i have done the above the above procedure on the sample data..and the value that i have obtained is wrong.. the test data is.. a=[10 8 10 9 20 21 32 30 40 41 41 40 12 10 11 10 19 20 30 28 38 40 40 39 10 9 10 8 20 21 30 29 42 40 40 39 11 10 9 11 19 21 31 30 40 42 38 40]; >> [n x]=hist(a,48); >> d=n/sum(n); >> cdf=cumsum(d); >> thri=find(cdf<0.361,1,'first'); >> thr=x(thri); >> thr thr = 8.3542 ...while the value of thr should be 18.. @Shai – user2081934 Feb 18 '13 at 08:35