Histogram thresholding to get the threshold point
古いコメントを表示
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
- I needed to choose threshold Value?
- I want to compare each pixel value with threshold value of a zero matrix of same size as image
- 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
x=imread('tumor.jpg');
% 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
採用された回答
その他の回答 (2 件)
Iman Ansari
2013 年 4 月 28 日
Hi.
% code
x=imread('tumor.jpg');
% 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 件のコメント
Muhammad Ali Qadar
2013 年 4 月 28 日
Muhammad Ali Qadar
2013 年 4 月 28 日
vetri
2014 年 9 月 29 日
I want to threshold my image by using kapur(max entropy) method..what to do?
Image Analyst
2014 年 9 月 29 日
I'd program it up in MATLAB. Can't you do that?
Vertika Jain
2016 年 11 月 6 日
Hello, i am working on matlab code for shadow detection and removal from aerial images using bimodal histogram splitting method for thresholding. can u plz help me with the code.
Image Analyst
2016 年 11 月 6 日
That seems like a really bad algorithm. You should look here: http://www.visionbib.com/bibliography/contents.html for published algorithms that work.
Here's some work that the University of Dayton has done on shadow removal: https://www.udayton.edu/engineering/centers/vision_lab/wide_area_surveillance/visibility_improvements.php
Vertika Jain
2017 年 1 月 18 日
Thanks for ur support. Now i am successfully able to detect the shadow in an image but unable to remove it. Can u plz help me.
Image Analyst
2017 年 1 月 18 日
Just add an offset, or multiply by a factor greater than 1, to raise the gray levels in the shadow regions.
Vertika Jain
2017 年 1 月 18 日
This is my detected shadow. Now how should i add an offset.
Vertika Jain
2017 年 1 月 18 日

Image Analyst
2017 年 1 月 18 日
Take your output image use it as a mask and add something to it. Something like
shadows = output > 250; % Find white areas
grayImage(shadows) = grayImage(shadows) + 100; % Add 100 to shadow areas.
Or multiply by a factor
brightnessFactor = 1.5;
grayImage(shadows) = uint8(double(grayImage(shadows)) * brightnessFactor);
Alex Taylor
2016 年 11 月 7 日
編集済み: Alex Taylor
2016 年 11 月 7 日
0 投票
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.
カテゴリ
ヘルプ センター および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
