please help me to figure out the problem in tree decision method coding below. the decision tree graph didnt appear. and to figure out the coordinate of weld bead in the sample picture that i attached together with the coding.

i=imread('5(a).jpg');
j=rgb2gray(i);
subplot(1,3,1);
imshow(j);title('original');
subplot(1,3,2);imhist(j),title('histogram');
level=graythresh(j);
level*255;
bw=imbinarize(j,level);
subplot(1,3,3);imshow(bw),title('otsu');
%% segmented the area needed
%[r c]=ginput (4); %border of the image position
c1 = [2.140000000000001e+02;...
2.100000000000001e+02;...
2.900000000000001e+02;...
2.850000000000001e+02];
r = [55;583;580;58];
BW = roipoly (bw,r,c);
[R, C]=size(BW);
for i=1:R
for j=1:C
if BW (i,j) == 1
I (i,j)= bw(i,j);
else
I (i,j)= 0;
end
end
end
figure;
imshow(I,[]);title('Segmented Image');
c1 = [2.140000000000001e+02;...
2.100000000000001e+02;...
2.900000000000001e+02;...
2.850000000000001e+02];
r1 = [55;583;580;58];
BW2 = roipoly (bw,r,c);
[R1 C1]=size(BW2);
for i1=1:R1
for j1=1:C1
if BW2 (i1,j1) == 1
I1 (i1,j1)= bw(i1,j1);
else
I1 (i1,j1)= 0;
end
end
end
%Display Figure
%Data extraction
img = I;
[CC, numberOfcircles] = bwlabel (img);
CC = bwconncomp(CC);
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
for num = 1:numberOfcircles
img(CC.PixelIdxList{num}) = 0;
img(CC.PixelIdxList{idx}) = 1;
end
measurements = regionprops (img,...
'Area',...
'Perimeter',...
'Centroid',...
'MajorAxisLength',...
'MinorAxisLength');
dCounting = numberOfcircles;
skelimg = bwmorph(img,'skel',Inf);
spurimg = bwmorph(skelimg,'spur',10);
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
spurimg = imdilate(spurimg, [se90 se0]);
B = bwmorph(spurimg,'branchpoints');
corners = detectMinEigenFeatures(B);
dBranches = size(corners);
dThickness = measurements.Area;
dThin = (measurements.Area / measurements.MajorAxisLength);
image = [dCounting dBranches(1) dThickness dThin];
fprintf('No. of Welding Area is %g\n', dCounting);
fprintf('No. of Branches for Welding Area is %g\n', dBranches(1));
fprintf('Size of Welding Area is %g\n', dThickness);
fprintf('Thickness of Welding Area is %g\n', dThin);

Answers (0)

Asked:

on 25 May 2021

Community Treasure Hunt

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

Start Hunting!