How can I select a ROI dynamically (automatically) ?

1 次查看(过去 30 天)
I deal with dental X-ray and want to segment the teeth from other tissue, I try canny, but unwanted results i got by using this code:
readim = imread('indiv1.jpg');
imwrite(readim,'indiv1.tif');
i=imread('indiv1.tif');
figure, imshow(i), title('original image');
BW = im2bw(i,0.6);
I = edge(BW,'canny');
figure, imshowpair(BW,I,'montage'), title('binary gradient mask');
[~, threshold] = edge(BW, 'canny');
fudgeFactor = .5;
BWs = edge(BW,'canny', threshold * fudgeFactor);
imshowpair(BW,BWs,'montage')
%%%%%%%%%%%%
%dilate the image
se90 = strel('line', 3, 90);%vertical structuring element// creates a flat linear structuring element
se0 = strel('line', 3, 0);% horizontal structuring element.
Idil = imdilate(I, [se90 se0]);
figure, imshow(Idil), title('dilated gradient mask');
and then try to use two step threshold composed of iterative thresholding and adaptive thresholding the first one i try the code below:
readim = imread('indiv1.jpg');
imwrite(readim,'indiv1.tif');
a=imread('indiv1.tif');
figure, imshow(a), title('original image');
i=rgb2gray(a);
AverageGrayValue = mean(mean(i));%=0.2311
%iterative thresh.
[ n, m ]=size(i);
newAverageGrayValue = 0.5;
while (newAverageGrayValue - AverageGrayValue)>0.1
for r=1:n
for c=1:m
if i(r,c) >= AverageGrayValue
R1 = i(r,c);
else
R2= i(r,c);
end
end
end
AverageGrayValue=newAverageGrayValue;
R1mean = mean( mean(R1));
R2mean = mean(mean(R2));
newAverageGrayValue=1/2 *(R1mean+R2mean );
end
T = AverageGrayValue;
bim=(i>T);
imshow(bim);
but the other threshold error message will appear after running this code:
readim = imread('indiv1.jpg');
imwrite(readim,'indiv1.tif');
a=imread('indiv1.tif');
figure, imshow(a), title('original image');
%AdaptiveT hreshold%%%%%%%%%
[R, C]=size(a);
for x = 0 : R
sumation = 0;
for y = 0 : C
sumation = sumation+a(x, y);
if x == 0
intImg(x, y)= sumation;
else
intImg(x, y)= ( intImg(x-1, y) +sumation);
end
end
end
%%%%%%%%%%%%%%%%%
error message is:
>> Untitled5
Subscript indices must either be real positive integers or logicals.
Error in Untitled5 (line 44)
sumation = sumation+a(x, y);
thanks for all

回答(1 个)

Image Analyst
Image Analyst 2015-9-28
编辑:Image Analyst 2015-9-28
See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F and then use the debugger and you'll be able to solve it yourself. Hint: there is no 0'th row or 0'th column - numbering starts at 1.
By the way, why are you calling rows x and calling columns y? Usually x is the horizontal direction and so x is columns, not rows. Using the most used convention, you do not index arrays as (x,y) but as (y, x) which is (rows, columns).

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by