Don't understand the following script for image evaluation

1 view (last 30 days)
Hey guys,
I have a script for image evaluation (for an image like in the attachment) and unfortunately I don't understand one part. The reading of the image I understand. I don't understand the middle part with "%%%%FINDING Lengths in TOP ROW" (I have marked the part boldly).
What exactly happens there?
Any help would be greatly appreciated!
________________________________________________________________________
,%referncesize=input('Please Enter Refernce size in nm/Pixel: ');
close all
clear
clc
referncesize=690;
%Opening image
[imagefiles ,pathname] = uigetfile({'*.bmp'},'MultiSelect', 'on'); inputimage=strcat(pathname, imagefiles);
files = string(inputimage);
imfiles = string(imagefiles);
for k = 1:length(files)
try
disp(files(k))
I = imread(files(k));
J=rgb2gray(I);
J = imadjust(J);
J = medfilt2(J);
level = graythresh(J);
BW=imbinarize(J,level);
BW = medfilt2(BW);
se = strel('disk',0,0);
erodedBW = imerode(BW,se);
%%%%% CHANGE HERE FOR OTHER RESULTS: USUALLY: [...]('disk',10,0)
se = strel('disk',0,0);
erodedBW = imdilate(erodedBW,se);
figure
imshow(erodedBW)
%%%%FINDING Lengths in TOP ROW
[row,column]=size(erodedBW);
startingpointr1=[];
endingpointr1=[];
startingflag=0;
tempflag=0;
for i=1:column
if erodedBW(1,i)==1
tempflag=tempflag+1;
if tempflag>5
if startingflag==0
startingpointr1=[startingpointr1 i];
startingflag=1;
end
end
else
if tempflag>5
startingflag=0;
endingpointr1=[endingpointr1 i];
end
tempflag=0;
end
end
%%%% FINDING LENGTH IN MIDDLE
startingpointr2=[];
endingpointr2=[];
startingflag=0;
tempflag=0;
for i=1:column
if erodedBW(row/2,i)==1
tempflag=tempflag+1;
if tempflag>5
if startingflag==0
startingpointr2=[startingpointr2 i];
startingflag=1;
end
end
else
if tempflag>5
startingflag=0;
endingpointr2=[endingpointr2 i];
end
tempflag=0;
end
end
%%%% FINDING LENGTH IN Bottom
startingpointr3=[];
endingpointr3=[];
startingflag=0;
tempflag=0;
for i=1:column
if erodedBW(row,i)==1
tempflag=tempflag+1;
if tempflag>5
if startingflag==0
startingpointr3=[startingpointr3 i];
startingflag=1;
end
end
else
if tempflag>5
startingflag=0;
endingpointr3=[endingpointr3 i];
end
tempflag=0;
end
end
%%%%%%%%%%%%%%%FIND COLUMN WISE WIDTH
startingpointc1=[];
endingpointc1=[];
startingflag=0;
tempflag=0;
for i=1:row
if erodedBW(i,1)==1
tempflag=tempflag+1;
if tempflag>5
if startingflag==0
startingpointc1=[startingpointc1 i];
startingflag=1;
end
end
else
if tempflag>5
startingflag=0;
endingpointc1=[endingpointc1 i];
end
tempflag=0;
end
end
%%%%%%%%%COLUMN WISE IN MIDDLE
startingpointc2=[];
endingpointc2=[];
startingflag=0;
tempflag=0;
for i=1:row
if erodedBW(i,(column/2))==1
tempflag=tempflag+1;
if tempflag>5
if startingflag==0
startingpointc2=[startingpointc2 i];
startingflag=1;
end
end
else
if tempflag>5
startingflag=0;
endingpointc2=[endingpointc2 i];
end
tempflag=0;
end
end
%%%%%%%%%COLUMN WISE IN END
startingpointc3=[];
endingpointc3=[];
startingflag=0;
tempflag=0;
for i=1:row
if erodedBW(i,(column))==1
tempflag=tempflag+1;
if tempflag>5
if startingflag==0
startingpointc3=[startingpointc3 i];
startingflag=1;
end
end
else
if tempflag>5
startingflag=0;
endingpointc3=[endingpointc3 i];
end
tempflag=0;
end
end
%startingpointr1
%endingpointr1
r1c1=endingpointr1(1)-startingpointr1(1);
r1c2=endingpointr1(2)-startingpointr1(2);
%startingpointr2
%endingpointr2
r2c1=endingpointr2(1)-startingpointr2(1);
r2c2=endingpointr2(2)-startingpointr2(2);
%startingpointr3
%endingpointr3
r3c1=endingpointr3(1)-startingpointr3(1);
r3c2=endingpointr3(2)-startingpointr3(2);
%startingpointc1
%endingpointc1
r11c1=endingpointc1(1)-startingpointc1(1);
r22c1=endingpointc1(2)-startingpointc1(2);
%startingpointc2
%endingpointc2
r11c2=endingpointc2(1)-startingpointc2(1);
r22c2=endingpointc2(2)-startingpointc2(2);
%startingpointc3
%endingpointc3
r11c3=endingpointc3(1)-startingpointc3(1);
r22c3=endingpointc3(2)-startingpointc3(2);
T1 = {'Position' 'Value (nm)';
'r1c1' r1c1*referncesize;
'r1c2' r1c2*referncesize;
'r2c1' r2c1*referncesize;
'r2c2' r2c2*referncesize;
'r3c1' r3c1*referncesize;
'r3c2' r3c2*referncesize;
'r11c1' r11c1*referncesize;
'r22c1' r22c1*referncesize;
'r11c2' r11c2*referncesize;
'r22c2' r22c2*referncesize;
'r11c3' r11c3*referncesize;
'r22c3' r22c3*referncesize;
};
T = cell2table(T1);
writetable(T,'data.xlsx','Sheet',imfiles(k),'WriteVariableNames',false)
catch
T1 = {'Position' 'Value (nm)';};
T = cell2table(T1);
writetable(T,'data.xlsx','Sheet',imfiles(k),'WriteVariableNames',false)
end
end

Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!