image intensity scale sub-divide into two ranges

1 回表示 (過去 30 日間)
Nataliya
Nataliya 2014 年 12 月 2 日
コメント済み: Thorsten 2014 年 12 月 2 日
I have an image. I obtain the histogram for that image and calculate probability distribution using the code below:
if size(I,3) == 1 %grayscale image
[n_countR, x_valueR] = imhist(I(:,:,1));
Nt = size(I,1) * size(I,2); %Total number of pixels in the image ROW X COL
%Lmax segmenting color levels 0-256
Lmax = 256; %256 different maximum levels are considered in an image (i.e., 0 to 255)
% Probability distribution for each intensity level histogram 0 - 256
for i = 1:Lmax
if size(I,3) == 1
%grayscale image
probR(i) = n_countR(i) / Nt;
end
Now I want this image histogram, having range 0 to 255, to sub-divide into two having the range 0 to 127 and 128 to 255 respectively and find probability distribution for both. Please help. I hope now you can better understand my question. Much thanks..

採用された回答

Guillaume
Guillaume 2014 年 12 月 2 日
編集済み: Guillaume 2014 年 12 月 2 日
By default, imhist on a greyscale image outputs 256 bins, just as you want. You then jut have to split this output in half, using simple indexing.
if size(I, 3) == 1 %in that case I(:,:, 1) == I
h = imhist(I); %histogram over 256 bins by default
hlow = h(1:128); %lower part of the histogram
hhigh = h(129:256); %higher part of the histogram
end
To convert to pdf over the total number of pixels, use matrix operations rather than for loops:
pdflow = hlow/numel(I);
pdfhigh = hhigh/numel(I);
or if you want pdfs over the population of each half-histogram:
pdflow = hlow/sum(hlow);
pdfhigh = hhigh/sum(hhigh);

その他の回答 (1 件)

Thorsten
Thorsten 2014 年 12 月 2 日
h1 = hist(I(I<=127), 0:127);
h2 = hist(I(I>=128), 128:255);
  4 件のコメント
Nataliya
Nataliya 2014 年 12 月 2 日
I have edit my question. Kindly review it and answer. I will be thankful to you
Thorsten
Thorsten 2014 年 12 月 2 日
ind = find(I < 128);
Plow = hist(I(I < 128), 0:127)/numel(ind);
ind = find(I >= 128);
Plow = hist(I(I >= 128), 128:255)/numel(ind);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by