thresholding for multiple values

조회 수: 9 (최근 30일)
Matpar
Matpar 2019년 8월 7일
편집: Matpar 2019년 8월 7일
Hi all i have my thresholding code here and i am trying to do a thresholding processing for multiple types of thresholding in the same go!!!
I am new and i am not sure if this is possible but can a professional assist me where I am going wrong and add comments so that I get the understanding of it!!
I am getting loads of errors and I am not sure where to beging as a beginner!!
Thanks in advance for you consideration and assistance!!!
*********** My Code *******************************
b=imread("bird.jpg");
Gbird=rgb2gray(sc);
t=mean(Gbird(:));
t1=meadian(Gbird(:));
t2=[50,100,150,200];
[r, c]=size(Gbird);
Msc=zeros(r,c);
for i=1:r
for j=1:c
if Gbird(i,j)>t,t1;t2;
Msc(i,j)=1;
end
end
end
imshow(Msc), figure;
imshow(Gbird), figure;
imshow(sc), figure;
subplot(1,3,1), imshow(sc), title('Binary Image Of The Car');
subplot(1,3,2), imshow(Gbird), title('Grayscalee Image Of The Car');
subplot(1,3,3), imshow(Msc), title('Original Image Of The Car');

답변 (2개)

dpb
dpb 2019년 8월 7일
t1=meadian(Gbird(:));
median is misspelled...
What do you want/expect as a result? Logicals don't work that way; you'll have to test for each level.
As written, even if the logical test worked, you would only have a '1' in the Msc array for all locations which had a value greater than the least of those in your list of various t* -- not a way to locate which would be greater than each threshold. To do that you would need to be able to store a logical plane for each of the levels--6 total so would need a r x c x 6 3D array.
The way to do something like this in ML would be to loop over the number of levels and do the logical test as vector operation. Something otoo--
...
thresh=[mean(Gbird(:));median(Gbird(:));[50:50:200].']; % the threshold levels desired
nTh=numel(thresh);
Msc=false([size(Gbird) nTh]);
for i=1:nTh
Msc(:,:,i)=(Gbird>thresh(i));
end
  댓글 수: 5
Matpar
Matpar 2019년 8월 7일
what i gathered from it is that they would like to to see all three!!!
please assist me with the code for the threshold equal to the values
t= 50, 100, 150, 200
the syntax is a bit challenging for me
I am trying to get an image to show for all of the values in the threshold
and use one subplot syntax for all the values rather than type them all out!!
hope that helps really need this to be solve
dpb
dpb 2019년 8월 7일
I don't understand what it means "for the threshold equal to the values", sorry.
Where did this come from? Can you show a link to the original?

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


Matpar
Matpar 2019년 8월 7일
Screenshot 2019-08-07 at 17.38.04.png
  댓글 수: 1
Matpar
Matpar 2019년 8월 7일
편집: Matpar 2019년 8월 7일
This is how far i have gotten but it seems like i am more confused than you are dpb!
b=imread("bird.jpg");
Gbird=rgb2gray(b);
whos
t=100;150;200
[r, c]=size(Gbird);
Msc=zeros(r,c);
for i=1:r
for j=1:c
if Gbird(i,j)>t
Msc(i,j)=1;
end
end
end
imshow(Msc), figure;
imshow(Gbird), figure;
imshow(b), figure;
subplot(1,3,1), imshow(b), title('Binary Image Of The Car');
subplot(1,3,2), imshow(Gbird), title('Grayscalee Image Of The Car');
subplot(1,3,3), imshow(Msc), title('Original Image Of The Car');

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

Community Treasure Hunt

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

Start Hunting!

Translated by