MATLAB: Whats the difference between the firstand 2nd part

zebra fish image analysis

clc
clear all
close all
warning('off','all');
cd C:\Users\student\Desktop\GUI_Larva\bentSpine
files=dir('*.TIF');
for i=1: length(files)
im=imread(files(i).name);
%figure,imshow(im),title('original image');

im1=imadjust(im,stretchlim(im),[]);
%figure,imshow(im1),title('maxcontrast image');

imth=graythresh(im1);
im2=im2bw(im1,imth);
%figure,imshow(im2),title('binary image');

se=strel('disk',2);
im3=imdilate(imcomplement(im2),se);
%figure,imshow(im3),title('expansion image');

im4=imerode(im3,se);
%figure,imshow(im4),title('erodent image');

im5=imclearborder(im4);
%figure,imshow(im5);

%s=size(im5);

%percentage=floor(s(1)*s(2)*);

imcc = bwconncomp(im5);
Zebrafishdata = regionprops(imcc, 'area');
Zebrafish_area = [Zebrafishdata.Area];
[max_area, idx] = max(Zebrafish_area);
if imcc.NumObjects>=2
Zebrafish = false(size(im5));
Zebrafish(imcc.PixelIdxList{idx}) = true;
im6=Zebrafish;
else
end
%figure,imshow(im6),title('maxObject image');

%format bank

status=regionprops(im6,'MajorAxisLength');
majoraxis_data{i}=[status.MajorAxisLength];
%if majoraxis_data{i}>900
output=cell2mat(majoraxis_data);
xlswrite('C:\Users\student\Desktop\GUI_Larva\MajorAxis.xls',output,'sheet1','A8');
%else

%end

%fid=fopen('C:\Users\weimeng\Desktop\blue.txt','at+');
%fprintf(fid, '%s %8.3f \n\n',files(i).name, error);
%fprintf(fid, '%8.3f \n\n',majoraxis_data);
%fclose(fid);
end
output1=cell2mat(majoraxis_data);
figure(),p=plot(output1);
set(p,'Color','blue')
title('Normal Larvae');
xlabel('Number of Lavae');
ylabel('MajorAxis(Pixels)');
%-------------------------------------------------------------------------------
cd C:\Users\student\Desktop\GUI_Larva\bentSpine
files=dir('*.TIF');
for j=1: length(files)
im=imread(files(j).name);
%figure,imshow(im),title('original image');
im1=imadjust(im,stretchlim(im),[]);
%figure,imshow(im1),title('maxcontrast image');
imth=graythresh(im1);
im2=im2bw(im1,imth);
%figure,imshow(im2),title('binary image');
se=strel('disk',2);
im3=imdilate(imcomplement(im2),se);
%figure,imshow(im3),title('expansion image');
im4=imerode(im3,se);
%figure,imshow(im4),title('erodent image');
im5=imclearborder(im4);
%figure,imshow(im5);
%s=size(im5);
%percentage=floor(s(1)*s(2)*);
imcc = bwconncomp(im5);
Zebrafishdata = regionprops(imcc, 'area');
Zebrafish_area = [Zebrafishdata.Area];
[max_area, idx] = max(Zebrafish_area);
if imcc.NumObjects>=2
Zebrafish = false(size(im5));
Zebrafish(imcc.PixelIdxList{idx}) = true;
im6=Zebrafish;
else
end
%figure,imshow(im6),title('maxObject image');
%format bank
status=regionprops(im6,'MajorAxisLength');
majoraxis_data{j}=[status.MajorAxisLength];
%if majoraxis_data{j}>900
output=cell2mat(majoraxis_data);
xlswrite('C:\Users\student\Desktop\GUI_Larva\MajorAxis.xls',output,'sheet1','A10');
%else
%end
end
output2=cell2mat(majoraxis_data);
figure(),q=plot(output2);
set(q,'Color','red')
title('Abnormal Lavae - BentSpine');
xlabel('Number of Lavae');
ylabel('MajorAxis(Pixels)');
figure()
p=plot(output1);
set(p,'Color','blue');
hold on;
q=plot(output2);
set(q,'Color','red');
title('Comparision');
xlabel('Number of Lavae');
ylabel('MajorAxis(Pixels)');
hold off;

Best Answer

  • The first part does
    clc
    clear all
    close all
    warning('off','all');
    but the second part does not.
    The first part uses "i" as the loop variable. The second part uses "j" as the loop variable.
    The first part writes the results starting at A8 of the spreadsheet. The second part writes the results starting at A10 of the spreadsheet. The amount of data to write varies each time. If you had 'ABCDE' and then '123' then the result would be '123DE'.
    The two parts generate different figures. In the first part the output is plotted in blue and the title is 'Normal Larvae'. In the second part the output is plotted in red and the title is 'Abnormal Lavae - BentSpine'. A figure named 'Comparision' is also generated that plots both at once. As the results will be exactly the same for both parts, it will not be possible to see the blue line.
    You did not ask about bugs in the code, only about what the difference between the parts is. None the less I would suggest to you that the major bug in the code is that both parts use
    cd C:\Users\student\Desktop\GUI_Larva\bentSpine
    Considering the title of the second plot, I suspect you will find that directory contains the data only for the abnormal larvae and that you should cd to a different directory for the normal larvae. Something like
    cd C:\Users\student\Desktop\GUI_Larva\normal