what is the function of these code?
4 views (last 30 days)
Show older comments
anyone can tell me what this run button do?
% --- Executes on button press in Run_btn.
function Run_btn_Callback(hObject, ~, handles)
% hObject handle to Run_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cd(handles.current_folder);
files=dir('*.TIF');
fid = fopen(strcat(handles.current_folder,'\eggResult.txt'),'wt+');
fprintf(fid, '\tFiles_Name\t\t Regression(r) Slope(m)\tOffset(b)\t Result\n\n');
fclose(fid);
maxconbar=waitbar(0,'1','Name','Processing Imgaes',...
'CreateCancelBtn',...
'setappdata(gcbf,''canceling'',1)');
a = 1;
for i=1: length(files)
if getappdata(maxconbar,'canceling')
break
end
b = length(files);
%Report file being process in waitbar message field
waitbar(i/length(files),maxconbar,sprintf(strcat( num2str(a) ,'/', num2str(b) ,' Processing:',char(files(i).name))));
a = a + 1;
% disp(strcat('Processing ',char(files(i).name)));
im0=imread(files(i).name);
im0=imadjust(im0,stretchlim(im0),[]);
s=size(im0);
im0=imcrop(im0,[floor(s(1)/4) floor(s(2)/4) floor(s(1)/2) floor(s(2)/2)]);
%figure,imshow(im0);
im1=im2bw(im0,graythresh(im0));
%figure,imshow(im1);
im1=imcomplement(im1);
%figure,imshow(im1);
im1=imfill(im1,'holes');
%figure,imshow(im1);
s=size(im1);
onepercent=floor(s(1)*s(2)*0.01);
im1=bwareaopen(im1,onepercent);
%figure,imshow(im1);
imcc=bwconncomp(im1);
%----------------------------------------------
Zebrafishdata = regionprops(imcc, 'area');
Zebrafish_areas = [Zebrafishdata.Area];
[max_area, idx] = max(Zebrafish_areas);
percentage=floor(s(1)*s(2)*0.16);
if max_area>=percentage
continue;
else
Zebrafish = false(size(im1));
Zebrafish(imcc.PixelIdxList{idx}) = true;
area{i}= max_area;
greyvector=im0(imcc.PixelIdxList{1});
greyvector=sort(greyvector);
%figure,plot(greyvector,'color','r')
y=double(greyvector);
y=y';
L=length(y);
t=1:L;
[r,m,b]=regression(t,y);
%[files_name]=files(i).name;
fid = fopen(strcat(handles.current_folder,'\eggResult.txt'),'at+');
string1='alive';
string2='dead';
if m>=0.2250
fprintf(fid, '%s %7.5f %6.4f %e %s\n\n',files(i).name,r,m,b,string1);
else
fprintf(fid, '%s %7.5f %6.4f %e %s\n\n',files(i).name,r,m,b,string2);
end
fclose(fid);
if m<0.2250
save{i}= m;
D=cell2mat(save);
% q=plot(handles.axes2,D);
% set(q,'Color','red')
% hold all;
else
store{i}= m;
A=cell2mat(store);
% p=plot(handles.axes2,A);
% set(p,'Color','blue')
% title('Alive(Blue) vs Dead(Red)');
end
%figure,plotregression(t,y)
end
end
delete(maxconbar);
q=plot(handles.axes2,D);
set(q,'Color','red')
hold all;
p=plot(handles.axes2,A);
set(p,'Color','blue')
set(handles.axes2,'XGrid','on');
set(handles.axes2,'YGrid','on');
title('Alive(Blue) vs Dead(Red)');
message = sprintf('%d images processed.', a-1);
uiwait(msgbox(message));
guidata(hObject, handles);
0 Comments
Answers (1)
Image Analyst
on 8 May 2015
Looks like it crops an image of zebra fish, then thresholds and does some particle size analysis. It then does some sort of regression on all the pixel locations of the biggest blobs and gets something called m (I don't have the regression() function so I don't know what that is), and decides if the fish is alive or dead based on if m is greater or less than 0.2250.
0 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!