rescale histogram

조회 수: 6 (최근 30일)
mohammed ABDEEN
mohammed ABDEEN 2012년 4월 30일
hello all !
i need to rescale the x-axis(gray levels) of a histogram from 0-1 to 0-255 ! can anyone help me ?! ,i need it coz i've to calculate pdf then.. thank you
  댓글 수: 2
Geoff
Geoff 2012년 4월 30일
Post the code you are having issues with. If you are using the 'hist' command, you can solve a lot of issues by using 'histc' to generate an array, and then draw it into a bar graph.
mohammed ABDEEN
mohammed ABDEEN 2012년 5월 1일
histc doesnt satisfy my needs, coz i've a histogram of an image where the grey levels are in this interval [0,1] and there are like 4 pulses in a different positions,and i want to normalize it between [0 255] so i would have these 4 pulses or whatever in an integer number and not fractional number ....

댓글을 달려면 로그인하십시오.

답변 (3개)

Image Analyst
Image Analyst 2012년 4월 30일
If your image has value in the range 0-255 then how did you get bins in the 0-1 range? You must be looking at an image that has been transformed, perhaps by im2double. Maybe you should just take the histogram of the original image, or else multiply the image you took the histogram of by 255 and cast to uint8 and take the histogram of that instead.
  댓글 수: 9
Image Analyst
Image Analyst 2012년 5월 2일
You still haven't convinced me, and I doubt you will. The probability values in the probability density function do not depend on the bin value. The probability values will of course depend on the width of the bins, and the location of the bins with respect to the true distribution, but simply scaling the bins (what you call i or gray level) will not change the PDF, and thus not change p in sum(p*log p), and not change entropy. Try it and see. If you don't see, ask me and I'll make a demo for you to prove it.
mohammed ABDEEN
mohammed ABDEEN 2012년 5월 3일
ok thnaks tomorrow i'll let u see what i'm doing i'll send u my code !

댓글을 달려면 로그인하십시오.


Geoff
Geoff 2012년 5월 2일
Still not sure I understand your motive completely...
But it seems like you have this situation:
data = rand(100,1);
bins = (1:4)/4 - 1/8;
hist(data, bins);
And you want this:
hist(data*256, bins*256);
set(gca, 'XLim', [0 256]);
set(gca, 'XTick', linspace(0,256,5));
  댓글 수: 10
mohammed ABDEEN
mohammed ABDEEN 2012년 5월 3일
ok i've missed the (.) in the formula . i did it!
mohammed ABDEEN
mohammed ABDEEN 2012년 5월 3일
but could u tell me ,which of these 2 codes is much better!
img1=img./255 % or img1=img.*255 ???
[counts x]=imhist(img1)
nz=find(counts)
p=count(nz)./(m*n) %m*n= number of pixels in img
sum(sum(p))
entropy=-sum(p.*log10p) % or log2 ???

댓글을 달려면 로그인하십시오.


Junaid
Junaid 2012년 5월 2일
I guess if you normalize your histogram, you will your desired output .. May be ?
As after normalizing your histogram, the sum of all values will be 1. That is actually you want (all values in Histogram will be in between 0-1).
Easiest way to normalize is to divide histogram by sum of histogram.
  댓글 수: 3
Junaid
Junaid 2012년 5월 3일
Oh... thanks for letting me know.
mohammed ABDEEN
mohammed ABDEEN 2012년 5월 3일
sorry junaid if i ddnt reply yet !! ... i'll write my code here after i've finished it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by