How can I select a ROI dynamically (automatically) ?

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일

0 개 추천

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).

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2015년 9월 28일

편집:

2015년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by