how to program a pushbutton and let it import all the tif file

this is how it should be done, but there is some error anyone know what is wrong with the coding?
% --- Executes on button press in Run_btn. function Run_btn_Callback(hObject, eventdata, 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);

1 Comment

Please format your code properly, when you want others to read it. And explain which error you see. It is very frustrating when you mention, that there is "some error" but do not offer any of the important details. You have the required information already, but all readers have to find out by their own, if you get an error message of if the results differ from your expectations.

This question is closed.

Asked:

on 16 Apr 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!