Hello, I'm undertaking a project that estimates the size of a crowd using image processing techniques. I'm experiencing difficulties in designing my gui to have different axes with the different stages of processing, e.g grayscale,edge detection.

I also want to enlist the use of list boxes with choices of the different image processing techniques as well as push buttons. Below is my code.
global im [path,user_cance]=imgetfile(); if user_cance msgbox(sprintf('Error'),'Error','Error'); return end im=imread(path); im=im2double(im); %converts to double axes(handles.axes1); imshow(im); imgray=(im(:,:,1)+im(:,:,2)+im(:,:,2))/3; axes(handles.axes1); imshow(imgray); hy=fspecial('sobel'); hx=hy; Iy=imfilter(double(imgray),hy,'replicate'); Ix=imfilter(double(imgray),hx,'replicate'); imgradmag=sqrt(Ix.^2+Iy.^2); axes(handles.axes1); imshow(imgradmag); se=strel('disk',20); Ie=imerode(imgray,se); Iobr=imreconstruct(Ie,imgray); axes(handles.axes1); imshow(Iobr); edgeim=edge(Iobr,'canny',[0.15 0.2]); axes(handles.axes1); imshow(edgeim); d=imdistline; [centers,radii]=imfindcircles(edgeim,[5 10],'sensitivity',0.92,'Edge',0.03); viscircles(centers,radii,'EdgeColor','b'); axes(handles.axes1); figure,imshow(edgeim); h=length(centers); Total=ones(240,320); figure,imshow(Total); hold on HDText=insertText(Total,[205 55],h,'AnchorPoint','LeftCenter'); imshow(HDText); text(25,55,'TOTAL : ','FontSize',12,'FontWeight','bold','Color','m'); hold off rgbImage=imread(im); imshow(rgbImage,'Parent',handles.axes1); imshow(imgray,'Parent',handles.axes2); imshow(imgradmag,'Parent',handles.axes3); imshow(Iobr,'Parent',handles.axes4); imshow(Total,'Parent',handles.axes5);

1 个评论

sorry the code copied wrongly. here is my code again.
global im
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
axes(handles.axes1);
imshow(im);
imgray=(im(:,:,1)+im(:,:,2)+im(:,:,2))/3;
axes(handles.axes1);
imshow(imgray);
hy=fspecial('sobel');
hx=hy;
Iy=imfilter(double(imgray),hy,'replicate');
Ix=imfilter(double(imgray),hx,'replicate');
imgradmag=sqrt(Ix.^2+Iy.^2);
axes(handles.axes1);
imshow(imgradmag);
se=strel('disk',20);
Ie=imerode(imgray,se);
Iobr=imreconstruct(Ie,imgray);
axes(handles.axes1);
imshow(Iobr);
edgeim=edge(Iobr,'canny',[0.15 0.2]);
axes(handles.axes1);
imshow(edgeim);
d=imdistline;
[centers,radii]=imfindcircles(edgeim,[5 10],'sensitivity',0.92,'Edge',0.03);
viscircles(centers,radii,'EdgeColor','b');
axes(handles.axes1);
figure,imshow(edgeim);
h=length(centers);
Total=ones(240,320);
figure,imshow(Total);
hold on
HDText=insertText(Total,[205 55],h,'AnchorPoint','LeftCenter');
imshow(HDText);
text(25,55,'TOTAL : ','FontSize',12,'FontWeight','bold','Color','m');
hold off
rgbImage=imread(im);
imshow(rgbImage,'Parent',handles.axes1);
imshow(imgray,'Parent',handles.axes2);
imshow(imgradmag,'Parent',handles.axes3);
imshow(Iobr,'Parent',handles.axes4);
imshow(Total,'Parent',handles.axes5);

请先登录,再进行评论。

回答(1 个)

I think that in order to program a GUI you need to get a different programming philosophy, e.g. OOP: I know it's an extensive subject, in the mean time, you can use this code wich is not OOP but will do it:
function myGUI
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im);
imgray=(im(:,:,1)+im(:,:,2)+im(:,:,2))/3;
handles.figure = figure('Name','MyGui');
handles.axes1 = axes('Position',[.05 .05 .4 .9]);
imshow(im) ;
handles.axes2 = axes('Position',[.55 .05 .4 .9]);
imshow(imgray);
end

类别

在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by