Percentile Method in Matlab

  • Follow


I am trying to create a method for percentile histogram in MATLAB. I have using cumsum function to get a cumulative histogram, but I am stuck on how to proceed afterwards. Any help. Below is my beginners code. Any help would be appreciated or at least some advise. I am not looking for someone to write the code. Just some hints on how to progress.

Novice to the MATLAB world
0
Reply aman (5) 12/15/2010 4:48:17 PM

aman <user@compgroups.net/> wrote in message <irSdnYO4CrjNbJXQnZ2dnUVZ_judnZ2d@giganews.com>...
> I am trying to create a method for percentile histogram in MATLAB. I have using cumsum function to get a cumulative histogram, but I am stuck on how to proceed afterwards. Any help. Below is my beginners code. Any help would be appreciated or at least some advise. I am not looking for someone to write the code. Just some hints on how to progress.
> 
> Novice to the MATLAB world
> 

Hi, Welcome to MATLAB! You did not include your code.

Wayne
0
Reply Wayne 12/15/2010 6:02:20 PM


Sorry about that, I missed the code and was not able to find anyway to edit the existing post..
Finally the code is:
I = imread('patient2.tiff');
%figure, imshow(I);
h = imhist(I);%image histogram
ch = cumsum(h);%cumulative histogram
plot(ch)


But I am not able to make any progress afterwards. How should I progress afterwards? 

Thanks
0
Reply aman (5) 12/15/2010 7:21:59 PM

aman <user@compgroups.net/> wrote in message <yr2dnZl0sr7LiJTQnZ2dnUVZ_jqdnZ2d@giganews.com>...
> Sorry about that, I missed the code and was not able to find anyway to edit the existing post..
> Finally the code is:
> I = imread('patient2.tiff');
> %figure, imshow(I);
> h = imhist(I);%image histogram
> ch = cumsum(h);%cumulative histogram
> plot(ch)
> 

Did you have something like this in mind?

 x = -3:0.1:3;
 y = randn(1e4,1);
 NumElements = histc(y,x);
 SumElements = cumsum(NumElements);
 bar(x,SumElements,'BarWidth',1);
 title('Cumulative Histogram');
 figure;
 bar(x,(SumElements./length(y))*100,'BarWidth',1);
 title('Cumulative Percentage Histogram');

MATLAB is a great tool!


Wayne
0
Reply Wayne 12/15/2010 9:06:11 PM

I may not have been clear in putting my question correctly. My situation is: need to extract facial bone structure from medical x ray image. now the idea is that bone percentage  value is about 20%. What I am trying to acheive is to remove 80% of the image using percentile histogram and keep just 20% which eventually gives me just the bone structure.

thanks
0
Reply aman (5) 12/15/2010 10:06:08 PM

Hi I have got some code to show you but everytime I post it it says that spam filter activated. any ideas on why this may be happening
0
Reply aman (5) 12/16/2010 2:12:43 AM

aman <user@compgroups.net/> wrote in message <PamdnWRYq7lSppTQnZ2dnUVZ_hydnZ2d@giganews.com>...
> I may not have been clear in putting my question correctly. My situation is: need to extract facial bone structure from medical x ray image. now the idea is that bone percentage  value is about 20%. What I am trying to acheive is to remove 80% of the image using percentile histogram and keep just 20% which eventually gives me just the bone structure.
> 
> thanks
> 

Let's assume X is your image and your image is 256x256. Make the necessary adjustments for your data.

% reshape the image into a vector for sorting
Y = sort(reshape(X,256^2,1));
% find the index correspoding to the cutoff for the top 20 percent
top20 = ceil(0.8*length(Y));
% find the threshold pixel value
threshold = Y(top20);
% find the indices in the original image corresponding to the top 20 percent
indices = find(X>=threshold);
% or if you don't want to include the threshold:  indices = find(X>threshold);
% create image of zeros to hold results
Z = zeros(size(X));
% fill the elements of Z with the top 20 percent values from X
Z(indices) = X(indices);

If you have the Statistics Toolbox, you can substitute the line

threshold = prctile(reshape(X,256^2,1),80);

for the three lines:

Y = sort(reshape(X,256^2,1));
top20 = ceil(0.8*length(Y));
threshold = Y(top20);


Hope that helps,
Wayne
0
Reply Wayne 12/16/2010 10:43:04 AM

hi wayne, thanks for the help, i will modify the code as per my requirements and will let you know how it goes, currently am at work so not able to much :(

thanks again
0
Reply aman (5) 12/16/2010 4:47:33 PM

Hi wayne, I modifed the code to fit my problem but I am having an error with the Z(indices) final value. It is just giving me on large value and that would not display as an image. for the size of the image i used the MATLAB tool:
[i j] = sixe(X); % X is the image
Y = sort(reshape(X, i*j, 1)); % i, j gives the size of the image

no luck.
any idea on what I may be doing wrong here...
0
Reply Aman 12/16/2010 8:56:50 PM

Aman <user@compgroups.net/> wrote in message <AKmdnchl0P6N4JfQnZ2dnUVZ_sednZ2d@giganews.com>...
> Hi wayne, I modifed the code to fit my problem but I am having an error with the Z(indices) final value. It is just giving me on large value and that would not display as an image. for the size of the image i used the MATLAB tool:
> [i j] = sixe(X); % X is the image
> Y = sort(reshape(X, i*j, 1)); % i, j gives the size of the image
> 
> no luck.
> any idea on what I may be doing wrong here...
> 
Hi Aman, please include your code and the size of your image. To see that the code works, just make an image of random variables.

X = randn(256,256);

Now, execute what I gave you.

Wayne
0
Reply Wayne 12/16/2010 10:48:04 PM

Hi Wayne,
thanks for the advise and help again, I have been able to diplay the image exactly as I wanted. I was trying to display the Z(indices) which was just giving me a line, but when I used imshow to display Z, it worked just fine. Thanks for all the help.

MATLAB Rocks, and You too :)
0
Reply Aman 12/17/2010 2:27:40 AM

16 Replies
806 Views

(page loaded in 0.176 seconds)

Similiar Articles:

















7/21/2012 6:03:10 PM


Reply: