# Histogram thresholding to get the threshold point

213 ビュー (過去 30 日間)
コメント済み: Image Analyst 2017 年 1 月 18 日
hi,
I have been on image segmentation, till now I have divided image into two parts then I have taken histogram of those two parts, after substracting two histograms
1. I needed to choose threshold Value?
2. I want to compare each pixel value with threshold value of a zero matrix of same size as image
3. and if threshold value is less than pixel value it woould be assigned 0
What have I done that is not correct upto some extent is given below
% im=rgb2gray(x);
im=x(:,:,1);
[q r]=size(im);
s=r/2;
for i=1:q
for j=1:s
%n1(i,j)=im(i,j);
end
end
for k=1:q
for m=s:r
% n2(k,m)=im(k,m);
end
end
if true
%code
n1 = im(:, 1 : end/2); %image(x,y,c) c is matrix displayed as image
n2 = im(:, end/2+1 : end );%indicate last array index
figure, imshow(n1)
figure, imshow(n2)
figure, imhist(n1)
figure, imhist(n2)
if true
%code
diff=imhist(n2)-imhist(n1);
figure, bar(diff,'r')
thresh_level = graythresh(diff); %find best threshold level
c=zeros(size(im));
[r c1] = size(im);
allpix=im(r, c1);
for i=1:r
for j=1:c1
if allpix(i,j)> thresh_level
c=255;
else
c=0;
end
end
end
figure, imshow(c)
end

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

### 採用された回答

Image Analyst 2013 年 4 月 28 日
I can't understand any rationale for that algorithm. What do you think thresholding the difference of the histograms will get you? What do you even think the difference of the histograms represents? Where did you come up with such an algorithm?
##### 3 件のコメント表示非表示 2 件の古いコメント
well said, here is the paper link http://www.ijeat.org/attachments/File/V1Issue4/D0235031412.pdf/ May be I have read some paper that don't have any reputation, or may be the algorithm is designed just to show off the some work have been done, you got the nature of paper I have read. I would be glad to know if you can share what others ways you have that would be better than this method? However, thanks a lot.

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

### その他の回答 (2 件)

Iman Ansari 2013 年 4 月 28 日
Hi.
% code
% im=rgb2gray(x);
im=x(:,:,1);
[q r]=size(im);
s=r/2;
% for i=1:q
% for j=1:s
% %n1(i,j)=im(i,j);
% end
% end
% for k=1:q
% for m=s:r
% % n2(k,m)=im(k,m);
% end
% end
if true
%code
n1 = im(:, 1 : end/2); %image(x,y,c) c is matrix displayed as image
n2 = im(:, end/2+1 : end );%indicate last array index
figure, imshow(n1)
figure, imshow(n2)
figure, imhist(n1)
figure, imhist(n2)
if true
%code
diff=imhist(n2)-imhist(n1);
figure, bar(diff,'r')
thresh_level = graythresh(diff); %find best threshold level
c=zeros(size(im));
[r c1] = size(im);
allpix=im;
allpix(allpix>thresh_level*255)=255;
allpix(allpix<=thresh_level*255)=0;
c=allpix;
% for i=1:r
% for j=1:c1
% if allpix(i,j)> thresh_level
% c=255;
% else
% c=0;
% end
% end
% end
figure, imshow(c)
end
end
##### 11 件のコメント表示非表示 10 件の古いコメント
Image Analyst 2017 年 1 月 18 日
shadows = output > 250; % Find white areas
Or multiply by a factor
brightnessFactor = 1.5;

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

Alex Taylor 2016 年 11 月 7 日

If you are trying to divide the 1-D feature space of grayscale values into 2 classes, that is exactly what the traditional Otsu thresholding algorithm does.
This algorithm is implemented in the MATLAB Image Processing Toolbox as greythresh:
This is the standard approach to global thresholding for binary image segmentation problems. I haven't looked at your paper.

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

### Community Treasure Hunt

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

Start Hunting!

Translated by