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);
endendfor k=1:q for m=s:r % n2(k,m)=im(k,m);
endendif 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 %codediff=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:c1if allpix(i,j)> thresh_level c=255;else c=0;end end end figure, imshow(c)end
Best Answer