Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
what happened to the following code?
조회 수: 1 (최근 30일)
이전 댓글 표시
in the following code i did image batch processing and then localization on that images on runtime 4 images are shown rea i.e real image,croped image,threshold and inverted image the problem is all thre images are showing correctly but in place of invertd image next real image is showing... kindli sort this out
code function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) alpha= str2double(get(handles.edit1,'String'));
pics=alpha; %no of pictures to be processed given by user
titl=0; %%helping to show title once
subplt=1; %%showing no of figures
% % MyCode
myFolder='C:\Users\Romesha\Desktop\2';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.bmp');
jpegFiles = dir(filePattern);
for i1 = 1:pics
baseFileName = jpegFiles(i1).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = cell(1, pics);
imageArray{i1} = imread(fullFileName);
imshow(imageArray{i1}); % Display image.
%drawnow ; % Force display to update immediately.
% try % Excel = actxserver('Excel.Application'); % catch a % Excel = []; % end % % set(Excel,'Visible',1);
im = imageArray{i1};
subplot(pics,4,subplt); %% subplot(no_of_columns,no_of_row,numbering_0f_pic_in_column) imshow(im);
h1 = text(-150, 105, sprintf( '%d)',i1));
if titl==0 title('real Image'); end
subplt=subplt+1;
[r c wid] = size(im);
if wid==1 k(:,:,1)=im; k(:,:,2)=im; k(:,:,3)=im; else k=im; end
pt = ginput(2);
x1 = pt(1,1); y1 = pt(1,2); x2 = pt(2,1); y2 = pt(2,2);
% xlswrite('excel.xls', [x2 y2], 1, sprintf('D%d',i1+1));
x = [x1 x2];
y = [y1 y2];
r = sqrt((x2-x1)^2 + (y2-y1)^2); % % xlswrite('excel.xls', r, 1, sprintf('F%d',i1+1));
for i=1:size(k,1) for j=1:size(k,2) x2 = j; y2 = i; val = floor(sqrt((x2-x1)^2 + (y2-y1)^2)); if(val == floor(r)) nim(i,j,1) = 255; nim(i,j,2) = 0; nim(i,j,3) = 0; BW(i,j) = 1;
else
nim(i,j,1) = k(i,j,1);
nim(i,j,2) = k(i,j,2);
nim(i,j,3) = k(i,j,3);
BW(i,j) = 0;
end
end
end
SE = strel('disk',1); BW3 = imdilate(BW,SE);
I2 = imfill(BW3,'holes');
for i=1:size(k,1) for j=1:size(k,2) if(I2(i,j)==1) ni(i,j,1) = k(i,j,1); ni(i,j,2) = k(i,j,2); ni(i,j,3) = k(i,j,3); else ni(i,j,1) = 0; ni(i,j,2) = 0; ni(i,j,3) = 0; end end end
ni = uint8(ni);
X1 = x1-r; X2 = x1+r;
Y1 = y1-r; Y2 = y1+r;
ROI = imcrop(ni,[X1,Y1,abs(X2-X1),abs(Y2-Y1)]); if wid==1 ROI = ROI(:,:,1); end
subplot(pics,4,subplt); imshow(ROI);
if titl==0 title('Croped pic'); end subplt=subplt+1;
%% thresholding level = graythresh(ROI); e= im2bw(ROI,0.5);
% level = graythresh(J); % e= im2bw(level,0.5); % subplot(pics,4,subplt); imshow(e);
if titl==0 title('threshold'); end subplt=subplt+1; %% invertinng image (taking complement of image) IM2 = imcomplement(e);
subplot(pics,4,subplt); imshow(IM2);
if titl==0 title('inverted image'); end subplt=subplt+1; %% locating Circle Using Hough Transfrom Rmin = 30; Rmax = 200; if titl==0 xlswrite('excel1.xls',{'center-Pupil-x' 'center-Pupil-y' 'RadiiPupil' 'center-Iris-x' 'center-Iris-y' 'RadiiIris'},1, sprintf('B1')); end [centersBright, radiiBright] = imfindcircles(IM2,[Rmin Rmax],'Sensitivity',0.9); cp=centersBright; % xlswrite('excel.xls', cp, radiiBright, sprintf('D%d',i1+1));
[centersDark, radiiDark] = imfindcircles(IM2,[Rmin Rmax],'ObjectPolarity','dark'); cd=centersDark; xlswrite('excel1.xls',[cp, radiiBright, cd, radiiDark] , 1 ,sprintf('A%d',i1+1));
t=viscircles(centersBright, radiiBright,'EdgeColor','b'); C2=viscircles(centersDark, radiiDark,'LineStyle','--'); %% Normalization % % c=ezpolar('1+cos(t)'); % imshow(c);
titl=titl+1;
end
function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
댓글 수: 1
답변 (1개)
Image Analyst
2014년 1월 25일
This will let you discover exactly what's happening: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!