MATLAB Image Processing: Show multiple images - matlab

Trying to experiment with MATLAB image filtering.
I take the image, use imshow(img), then apply a filter or some other transformation and call imshow(img) again.
For some reason, MATLAB seems to only display the image once, even if I call imshow or imagesc multiple times.
When I did this in Python, when I closed the image window, then the next image would appear. So I thought that until I closed the image window, code execution would halt. But that does not seem to be the case for MATLAB, as closing the image does nothing.
Anyone know why? Thank you.

Related

Matlab: Export a figure made with myaa

I am trying to get better quality phase plots of complex functions made with the Complex Function Explorer of E. Wegert CFE. For this purpose I apply the Matlab anti-aliasing function myaa.m to the phase plots that are made with the CFEGUI.m. For the example screenshot of the result window below I used the setting myaa([8 8]) in the Matlab command window which means that the supersampling enlarge the figure 8x and then downscale it to 1/8 to get the original h x w.
As one can see the window of the figure has no operation icons or menu options for save or print. My question is what to do with such a figure (beside making screenshots)? Can I somehow use export-fig to save such a figure or load it in an image array and if yes, how?
It is also possible to use the setting myaa([8 1]) which results in a very large figure window that is larger than my screen (and has the unpleasant attribute that it can not be moved). It would be even better if such a whole figure could be saved (not only the visible part).
You can use getframe to grab current figure information in pixels.
However, while I do not know how this affects you, notice that MATLAB versions above 2014b (included) have already anti-aliasing. The code you linked seem to be from 2008, I am not 100% sure if it has become obsolete now.

Matlab hide imtool window

I'm using imtool in Matlab to do some things like finding circles in a large image. In my case it works better than imshow, cause I can load larger images without reduceing the resolution (which caused problems regarding to find specific circles). To speed up the program I wonder if I can hide the window which will open when I use imtool. In my case imshow didn't work (besides not showing it), cause it always changes the zoom to fit the picture according to the screen.
Rather than using imtool (since you don't seem to need the tools), you can just manually specify the InitialMagnitifcation of imshow to prevent it from automatically scaling
imshow(data, 'InitialMagnification', 100)

Why does Matlab set the background white when saving a scope printed to figure?

I want to programmatically 'Print to figure' a Simulink scope and save the resulting figure to a folder.
Consider following Simulink model and select the scope:
I run following code (inspired by this question):
scopeName=get_param(gcb,'Name');
hs=findall(0,'Name',scopeName);
hf=figure(1);
hp=findobj(hs.UserData.Parent,'Tag','VisualizationPanel');
copyobj(hp,hf)
filename='test.tiff';
print('-dtiff',filename);
Although both the scope and the figure have a black background
the saved file has a white background
Is there something wrong with the print command or with something else?
By default, MATLAB inverts the background colors when printing to a figure. To get around this, you can set the InvertHardCopy to 'off'
set(gcf, 'InvertHardCopy', 'off')
Doing this (as opposed to using getframe) results in a much higher resolution image as getframe simply saves the figure at screen resolution (72dpi).
Another option is to use export_fig from the MATLAB file exchange to save the figure which will more reliably reproduce the image that is on your screen.
You can get the same view as you see:
img = getframe(gcf);
imwrite(img.cdata,'test.tiff');

Matlab imwrite() quality

I'm very new to Matlab, though I know a few other programming languages, so please forgive me if this is something simple. I have not been able to find any answers to this, either on StackOverflow or elsewhere.
I produce a figure using the following code:
figure(6),imageplot(P); drawnow;
Which looks like this:
I then save this image to my computer using the following commands:
imwrite(P, 'images/plot.png');
And the resulting image is tiny, and missing some of the color information:
If, however, I utilize the save function in the open figure (image #1) and save it manually, I get exactly what I want, which is that exact image stored on my computer.
How would I program that? I assumed that imwrite() would just write the image directly, but apparently I'm doing something wrong. Any advice? Perhaps it has something to do with the imageplot command? I cannot seem to get that to work in imwrite.
Update: Based on the comments below, I have begun using "imresize" with the "nearest" option. This scales the image properly, but the resulting image is still curiously darker (and therefore has less information) than if I hit the "save" button in the figure.
Image saved from figure:
Image using "imresize" with "nearest" option:
The MATLAB imwrite command saves exactly the number of pixels as specified in your image matrix. This is the actual result of your computation; the reason the output is "tiny" is because it is supposed to be. To make it larger, would be to simply scale/zoom it as required.
The save figure option however does something quite different: it rasterizes the the output you obtain in the figure window and gives you the option for saving it as an image. This is evident in the fact that when you do so, you obtain a white background in addition to your result which is really just the grey background you see before you save it; this can be adjusted by resizing the figure window before utilizing the save option.
If you're looking to simply make the output figure larger, I would recommend using something along the lines of the imresize command.
Say, if you want the default size to be twice the size of the real result, simply use:
imresize(P, 2.0);
For more options, try help imresize.
The command you need for the "Save As..." functionality of figures is called "print". I often use
print(gcf, '-dpng', 'some_filename.png')
or
print(gcf, '-depsc', 'some_filename.eps','-r0')
to save a figure as it is shown on screen. The format png offers a small filesize and excellent quality, and it is understood by most image viewers and browsers. The eps format is a vector format, which I use for printig. The '-r0' option specifies "use the same size as given by the screen resolution" for the vector format properties.

Matlab imshow() not showing the image properly

I have a simple code to show an image in Matlab. I use imread() to read it and imshow() to show it. the code it below, and the result in not shown properly. hope someone can help me.
img = imread('/home/samuelpedro/Desktop/API - Projecto/coimbra_aerea.jpg');
figure, imshow(img);
the resulting image is below.
also, if i choose to save it to file as a new jpg it is saved correctly.
UPDATE 1:
weirdly if i choose to show the axes in the preferences>image processing, it is corrected
Locking at your screen-shot, the x- and y-ticks are missing. They should appear in a standard-configuration of Matlab. Maybe something is just messed up in the Matlab-configuration. Try to do this with a clean new ~/.matlab folder (rename the old one before).
Alternatively ... again judging by your screen-shot, this looks like Ubuntu/Unity in the background. Unity needs acceleration (OpenGL), which can be randomly buggy for some Linux graphics drivers. You may want to try to launch matlab in a "clean" X-server (maybe the twm environment) to rule this out.
Save the image as an (uncompressed) bitmap (bmp) and read it with imread. If the jpg is messed up by the imread-routine, this should rule this out.
Last but not least, broken copy of your jpg on your disk, some flipped bits. Run md5sums on your file's copies.