How to Creat MATLAB GUI for this code? - matlab

Hi everyone I wrote this code using MatLab and I need to design a GUI as the following
Draw Button: to draw the path.
Scan Button: If I want to take an image using "Image Acquisition"
Static Text : to show the angels,number of objects and the centers (Individual)
Axes : To show the image after the processing
And is there any reference I should read to help me??
The Code:
im1=imread('C:\Users\Shadow Of Dark\Desktop\sample','jpeg');
im1=rgb2gray(im1);
level=graythresh(im1)
bwfram3=im2bw(im1,level);
bw2=bwareaopen(bwfram3,20);
se=strel('disk',10);
bw2=imclose(bw2,se);
bw2=imcomplement(bw2);
[labeled,numObjects] = bwlabel(bw2,4);
imshow(labeled);
numObjects
info=regionprops(labeled,'all');
centers=cat(2,info.Centroid)
hold on;
angles=zeros(1,numObjects);
j=0;
for i=1:2:2*numObjects-2
l = line([centers(i) centers(i+2)],[centers(i+1) centers(i+3)]);
set(l,'linewidth',3,'color','r');
angles(1,i-j)= atan((centers(i+1) - centers(i+3))/(centers(i) - centers(i+2)))*180/pi;
j=j+1;
end
angles

Firstly, draw in a paper (or Enterprise Architect, ...) what you want and where in the layout. Afterwards, think of the sequence diagram of your process and write it in a paper. Later, divide your code into some functions, related to the steps you have described. Then, create a GUI with the GUI Editor in MATLAB and add a graphical element to your layout. Finally, link each function you have described to your graphical element (read the official help to do it).
(Alternatively, you can do it quicker mixing all these steps, but it is not an appropriate way of doing it).

I find this list to be quite usefull for getting started:
http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples
You may also want to look at the examples that are already included in matlab.
Go to Start > Matlab > GUIDE

Related

Matlab GUI, create two tabs

I want to create two tabs within one GUI. One can show the plot of sine function, the other shows cone function. I can handle these two functions. but i do not know how to create two tabs. Thanks a lot!
If by tabs you mean 'plotting area' then you likely need to create 2 axes objects and display each plot in its own axes. In GUIDE it's very easy...more info here.
Let's say you have axes1 and axes2, you can do this:
axes(axes1) % Make axes1 the current axes.
plot(sin(...))
axes(axes2) % Make axes2 the current axes
plot(...)
and that's it. Hope this is what you mean! If not sorry I misunderstood the question.
EDIT
I thought about it and I'm probably wrong about what I thought a tab is. Matlab does not allow to do it directly, although it might be possible with the GUI Layout Toolbox. Here is a submission from the FIle Exchange which could be interesting to you: link here!. Sorry abut the confusion.
uitab() can be used for creating tabs. If you want to create tabs using guide it's currently not natively supported but possible with a work around I described here.

Matlab: How to interact with a graph to define a range via GUIs

I'm currently trying to make a GUI that will allow a user to select a range of x-values, limited to a set of predefined "markers" that can appear on the graph of some data. The Matlab program has a bunch of data that's already delimited with some number of markers, and will ask the user to choose two of these markers as a start and stop point, and then continue from there.
My question is whether or not Matlab has a built-in function or object that will place some kind of interactive marker on the plot (preferably on the bottom of the graph so that it doesn't obscure the data) that the user can click on so that I can get a call-back function from it and see which marker the user chose (and also perhaps have the ability to change its color and such to represent its selection).
Preferably the answer will not involve any add-ons, but any answer and any help would be greatly appreciated. Thank you!
Here is a very simple example using ginput, which asks the user to select a starting and ending points from which to plot the data.
clear
clc
close all
x = 1:15*pi;
figure
plot(x,sin(x),'LineWidth',2);
uiwait(msgbox('Select a start and finish point'))
a = zeros(1,2);
[a,~] = ginput(2);
xStart = a(1);
xFinish = a(2);
set(gca,'XLim',[xStart xFinish],'XTick',round(xStart):1:round(xFinish))
Is it something like this you had in mind? Do you really need a callback or is this sufficient? If not could you elaborate on what kind of markers you would need?
Hope that helps!

add simple geometric elements to GUIDE GUI

I am desiging a simple GUI application in Matlab using GUIDE.
I am displayed a number of axis - and I would like to add some simple design elements to make the interface clearer. I would like to draw a colored rectangle around an axis (seperate from the axis)... there are two such axes, each displaying details of some things shown in a third plot, and I would like this color clue to link the details to the overview.
So is it possible to add simple geometric shape objects to a Matlab GUI? I don't see anything but controls in GUIDE but perhaps its possible to add them manually with an explicit command?
It is generally difficult to draw any random shape. Except Square & rectangle, for which you can create panels and change the properties like BorderWidth and HighlightColor.
Since MATLAB GUI is based on Java, you can create any object in MATLAB GUI which can be created in Java. You can refer to this website [1] for further learning.
[1] http://undocumentedmatlab.com/matlab-java-book/

How to manually segment and label ROIs in an image in Matlab?

I'm a newbie to Matlab. I'm basically attempting to manually segment a set of images and then manually label those segments also. I looked into the imfreehand(), but I'm unable to do this using imfreehand().
Basically, I want to follow the following steps :
Manually segment various ROIs on the image (imfreehand only lets me draw one segment I think?)
Assign labels to all those segments
Save the segments and corresponding labels to be used further (not sure what format they would be stored in, I think imfreehand would give me the position and I could store that along with the labels?)
Hopefully use these labelled segments in the images to form a training dataset for a neural network.
If there is some other tool or software which would help me do this, then any pointers would be very much appreciated. (Also I am new to stackoverflow, so if there is any way I could improve on the question to make it clearer, please let me know!) Thanks!
Derek Hoiem, a computer vision research at the University of Illinois, wrote an object labelling tool which does pretty much exactly what you asked for. You can download it from his page:
http://www.cs.illinois.edu/homes/dhoiem/software/index.html

How to create axes in matlab GUIDE

I want to implement the following code using matlab GUIDE:
axes(handles.axes1);
imshow(image1);
axes(handles.axes2);
imshow(image2);
As I am very new to GUIDE so I am having no idea how to do this. Any guidance.
Open guide selecting empty gui
Drag and drop two axes objects anywhere in the figure.
Right clicking on any axes object and seeing it properties allows to set size, position, and name of the object.
Guide always generate figure file in parallel with .m file containing all callback functions, among them function to be called on opening the gui (just before it is visible) -you can put you imshow() code there...
The whole thing is very intuitive, and has a great help provided by matlab.