whats the difference between the firstand 2nd part?

1 view (last 30 days)
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;
  2 Comments
Guillaume
Guillaume on 30 Jun 2015
Please use the formatting tool available to you. In particular the {} Code button to format the parts of your post that are code as code. As it is, it's impossible for us to know what is the first and second part you're referring to.
Jan
Jan on 30 Jun 2015
Please do not let us guess all details. Explain, what kind of difference you are searching for and what "parts" you are talking of. What do you observe?
What is the difference between a black bird?
Both legs have the same length, especially the right one.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Jun 2015
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!