Conversion to double from struct is not possible with bwconncomp

조회 수: 2 (최근 30일)
M
M 2014년 2월 13일
편집: M 2014년 2월 17일
So have this code but it keeps giving me an error at the bwconncomp line that says, Conversion to double from struct is not possible
for l=1:256 for m=1:256 for n=1:50
if (IMG(l,m,n) > 0.001)
if (( IMG(l,m,n) > 0.001)&&(IMG(l,m,n) < 0.19))
IMG(l,m,n)=1;
else
IMG(l,m,n)=0;
end
end
end
end
end
cc = zeros(256,256,50);
IMGT = zeros(256,256);
for ii = 1:50
IMGT=IMG(:,:,ii);
cc(:,:,ii) = bwconncomp(IMGT);
end
Any idea where the problem can be?

답변 (1개)

Image Analyst
Image Analyst 2014년 2월 13일
That's not a good way to binarize if you're simply comparing to a threshold.
Explain exactly what "didn't work for me" means. Do you get an error message?
  댓글 수: 4
M
M 2014년 2월 16일
for l=1:256 for m=1:256 for n=1:50
if (IMG(l,m,n) > 0.001)
if (( IMG(l,m,n) > 0.001)&&(IMG(l,m,n) < 0.19))
IMG(l,m,n)=1;
else
IMG(l,m,n)=0;
end
end
end
end
end
So its like a band pass filter to pass some frequencies and turn them into white, and set the rest to black.
Image Analyst
Image Analyst 2014년 2월 16일
That's not going to turn it into a structure. Anyway the whole thing (triple nested for loop) can be done a lot faster simply by doing this single line
IMG = IMG > 0.001 & IMG < 0.19;
No for loops needed at all. You should learn how to write vectorized code.

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by