Y-axis flip issue - Matlab App designer GUI - matlab

Based on this question Calculate Y coordinates of an image from graph point of origin I tried to do the same in app designer GUI but it does not work. I attached an image that shows that the image does not start from graph point of origin and that I get a new figure due to the set command. Any idea how to fix/do it?
Code:
function ButtonPushed(app, event)
url='https://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/512/owl-icon.png';
I = imread(url);
I = rgb2gray(I);
I=flipud(I);
imshow(I,'Parent', app.imageAxes);
set(gca,'YDir','normal')
end

gca creates a new figure window and a new set of axes if there are none. In particular, the app designer window is not a figure window, and so a new one is created.
But you don’t need to use gca to get a reference to your axes, since you already have the reference in app.imageAxes. This will set your axes to have a normal orientation:
set(app.imageAxes, ,'YDir', 'normal')
This should be the same as
app.imageAxes.YDir = 'normal';

you could try to import the image data as a 2-dimensional grid, and then flipping it.. could work not sure.

Related

How to force drawnow Matlab GUI to draw in new window?

I have used drawnow to draw the characters of the mnist dataset.. which outputs the following output
when i created GUI with matlab and calling drawnow to display images after loading it draws the figure on the open window giving the following output
my question is how to force it to draw in new window ?
drawnow only asks Matlab to flush the event queue and update figure windows; it doesn't determine how and where things are plotted. It's hard to tell since you don't include any code, but in your case it looks like you just plot the character images and the GUI elements into the same figure.
You can control which figure window a graphics operation refers to by setting the "current figure", whose handle is always contained in the variable gcf (graphics: current figure).
You generate a new figure and make it current by calling
figure
If you want to later make this figure current again, you need to save its handle:
fa = figure;
You then make a figure with a given handle current again by
figure(fa)
Some rough sketch of a possible program:
% generate figure windows
fa = figure;
fb = figure;
% plot something in figure a and make the screen update
figure(fa)
plot(...)
drawnow
% put a UI element into figure b and make the screen update
figure(fb)
uicontrol(...)
drawnow

MATLAB Graphing plots with axes

I have been trying to Create a program with the GUI in MATLAB. When I try to plot information with AXES I can not figure out how to do it. I know about the function plot, but I need to be able to re-size and move the plot around in the figure so I can make room for the input uicontrol. I am not sure what to do. Please help.
There are a couple of different ways to tackle this problem. But the way I always choose to do so, is:
hold on:
plot(...), xlim([xmin xmax), ylim(ymin ymax])
This should set your bounds on the axis.
I don't have Matlab at hand right now, but try the following:
To set size of the plot axes inside the figure window use
set(gca,'Position',[left bottom width height])
see Mathworks' site on axes properties

How do I hide axes and ticks in matlab without hiding everything else

I draw images to axes in my matlab UI, but I don't want the axes and ticks to be visible how do I prevent that, and also where do I make this call?
I do this
imagesc(myImage,'parent',handles.axesInGuide);
axis off;
Is this what you are looking for?
This is definitely somewhere else on this website and in the matlab documentation. Try typing
help plot
Or using the documentation on plotting!
edit: Now that you have shown what you are doing. (You don't need the handles, I just always write them in to clutter my workspace)
myImage = yurbuds0x2Dironman; # don't ask
fH = figure;
iH = imagesc(myImage);
set(gca,'xtick',[],'ytick',[])
Are you able to do it like this?
I support the
set(gca,'xtick',[],'ytick',[]);
approach over the
axis off
one. The reason is set(gca, ...) just removes the labels but keeps the axes, unlike axis off. I am generating a group of images with fixed dimensions to combine later into a video. Deleting the axes creates different size frames that can't be recombined.

Matlab image display in specific old figures

Take an example, I have 2 a sequences of left and right images: left01, right01, left02, right02, etc. How can I display those on only two figures: left and right. Each loop, these 2 figures will be updated with leftxx and rightxx.
"Hold on" will only hold the current figure. Creating figures with figure('Name', 'Left') will not do the trick, as multiple "Left" figures will be created. Yet imshow() does not let me specify the figure to display based on its name.
What I want is something similar to OpenCV, which let you choose which figure (already opened) to display
cvNamedWindow("Left");
cvShowImage("Left", myLeftImg);
"Left" figure will be updated with new img without creating new figure.
Thanks a lot.
Ken.
You need to save a handle on the axes-object within the figure and you need to tell the image-function to precisely which axes you want it to draw.
Try something along the lines of:
figure, h_r = axes;
figure, h_l = axes;
for n=1:whatever
image(right_bitmap, 'Parent', h_r, ...);
image(left_bitmap, 'Parent', h_l, ...);
drawnow;
end;
Update: image expects the handle as property 'Parent' rather than as first parameter.

MATLAB ButtonDownFcn

I have a project of "Optical Character Recognition" in MATLAB and i need your help:
how do i recognize when the user press the mouse on an image?
i trying to do this with ButtonDownFcn but even when i just printing message
the message is not printed.
i want to allow the user to select the license plate from the image.
how can i do this and save the Pixels of the selected area?
thanks in advance.
Addressing your two questions:
I'm guessing that you are trying to set the 'ButtonDownFcn' of the figure window, which won't work how you expect it to. If you want to do something when the user clicks on an image, you should make sure that you're setting the 'ButtonDownFcn' of the image, and not the figure window or the axes object. Note this line in the figure property documentation (emphasis added by me):
Executes whenever you press a mouse button while the pointer is in the figure window, but not over a child object (i.e., uicontrol, uipanel, axes, or axes child).
This is why you have to set a 'ButtonDownFcn' for each object you want it to work for. Setting it for the figure window won't make it work automatically for each object in the figure. Here's an example that sets the 'ButtonDownFcn' for the figure and an image object:
img = imread('peppers.png'); %# Load a sample image
hFigure = figure; %# Create a figure window
hImage = image(img); %# Plot an image
set(hFigure,'ButtonDownFcn',... %# Set the ButtonDownFcn for the figure
#(s,e) disp('hello'));
set(hImage,'ButtonDownFcn',... %# Set the ButtonDownFcn for the image
#(s,e) disp('world'));
Notice how clicking inside and outside the image displays a different message, since each calls the 'ButtonDownFcn' for a different object. Notice also that if you click on the tick mark label of one of the axes, nothing is displayed. This is because the axes object has its own 'ButtonDownFcn', which wasn't set to anything.
If you have access to the Image Processing Toolbox you can use the function IMFREEHAND to have the user draw an ROI (region of interest) in the image. Then you can use the createMask method to create a binary mask of the image with ones for pixels inside the ROI and zeroes for pixels outside the ROI.