imshowpair function - matlab

Is it possible to use imshowpair function in MATLAB to display images next to each other instead of over one another?
So far I have:
figure;
imshowpair(imgA, imgB, 'diff');
I have about 100 images I would like to display. Is it possible?

Indeed it is possible.
imshowpair(im1, im2, 'montage')
It only displays 2 images, though. If you need to display many images of the same size use the montage function.

you also can use
newImg = cat(2,img1,img2);

Related

Matlab border around figure

In attached image the output looks boring to me. Is it possible to have the subplots enclosed in a border?
Note: This question is not specific to publishing only but in general, say for exported images also.
Thanks
Postscript: I actually need this:
You can add a box like in here
making your code:
close all
figure()
padd=0.04
axes('Position',[padd padd 1-padd*2 1-padd*2],'xtick',[],'ytick',[],'box','on','handlevisibility','off')
subplot(1,2,1)
imagesc(magic(2))
subplot(1,2,2)
imagesc(magic(3))
This yields
And you can change the padd to be bigger or smaller
I obtained this just by plotting lines of different thickness 1.
The text was added with Inkscape though.
If I understand correctly what you want to do, you can obtain borders inside a figure using uipanels http://www.mathworks.com/help/matlab/ref/uipanel.html like this:
Code is:
u=uipanel('Title','MainPanel')
u1=uipanel('Parent',u,'BorderType','line','HighlightColor','k','Title','Subpanel 1','Position',[0,0,0.5,1])
u2=uipanel('Parent',u,'BorderType','line','HighlightColor','k','Title','Subpanel 2','Position',[0.5,0,0.5,1])
axes1=axes('Parent',u1)
imagesc(magic(2))
axes2=axes('Parent',u2)
imagesc(magic(3))
Of course you can change border widths, colors, titles and such

Save image from imshow

I want to save the image to a file after doing imshow(im,[]); to display it later in GUI. I am trying the following code, but it doesn't work.
New= imshow(uint8(MHI{t}),[]);
imwrite(New,'TMHI.jpg','jpg')
Any help will be appreciated. Thank you.
The imshow function is only used to show the image in MATLAB. If you want to save it, you don't need the imshow at all. And: the value (New) returned by imshow() is the handle to the figure. You need that handle if you want to modify how the figure is shown on the screen.
To write the image to the disk, you only need the imwrite function, which has the syntax:
imwrite(A,filename)
where A is the image array.
If the file name ends with .jpg, then MATLAB will create a JPEG image by default, so you don't need to specify that. (But of course, you still can.)
But before saving: you have a problem with the normalization of the image. MATLAB assumes that a double image is scaled to [0,1] and that a uint8 image is scaled to [0,255]. With imshow(im,[]) you override these defaults and make MATLAB calculate new values. You will experience the same problem when saving. The solution is to normalize the image properly. This can be done using the im2uint8 function, which scales the input to a maximum value of 255, and converts it to uint8. Note that you'll have to remove the minimal value manually, if that is needed:
newImage = im2uint8(MHI{t} - min(MHI{t}(:)));
imwrite(newImage,'TMHI.jpg')
In case you really need to save the contents of the displayed figure in matlab (sometimes also useful when you use imagesc for display as it has some smart logic for properly scaling your value ranges) you might be interested in the savefig and saveas which lets you save the contents of a figure. Its also possible to save graphs or figures with subfigures like that.
In that case, you would use something like:
F = imshow(uint8(MHI{t}),[]);
saveas('MHI.png');
In case you really just need to save the image stored in MHI{t}, hbaderts 's answer is the way to go...
Just use my NormalizeImage function and save the image normaly:
img = NormalizeImage(imgDouble);
imwrite(img ,'MyImage.png');
My NormalizeImage function:
function img8bpp = NormalizeImage(imgDouble)
minImgDouble = min(imgDouble(:));
factor = (255-0)/(max(imgDouble(:)) - minImgDouble);
%img8bppB = im2uint8(imgDouble-minImgDouble);
img8bpp = uint8((imgDouble-minImgDouble).*factor);
%im2uint8 does not work, duno y
%imgDif = img8bppB - img8bpp;
end

How to make a montage of different-sized images

I'm trying to make a montage of figures in Matlab, each figure comprising a row - I have about 12 rows in total. I tried making the whole thing with subplot but the resolution is limited by the screensize and too low. Then I tried saving each figure as an image, using export_fig, and arranging these with subplot but again the resolution is too low. So then I tried montage, but it expects the images to be the same size and they aren't quite (height varies slightly), and export_fig doesn't seem to have the option to control the crop size. If anybody has any solutions I would be grateful!
This is my suggestion:
First resize your images to the same size.
For example,
B = imresize(A, [512 512]);
Second you can use montage or you can use imgdisp
Imgdisp gives you more options than montage. You can consider using it..

how to save imageof axes for high resolution in matlab GUI

I trying save image with the comand 'getframe' but resolution is very low, so I can not give zoom. for now I'm using the code:
[arq,dir] = uiputfile('*.jpg','Output Files');
fileName=fullfile(dir,arq);
f=getframe(handles.axes1);
[x,map]=frame2im(f);
imwrite(x,fileName,'jpg');
I need save in jpg and also need save the label (x,y) in graph. How do ? There is another command better than the getframe??
Print is a good command?
Thanks
try using something other than jpg, it doesn't scale well. eps is a good choice as it is a vector format.
Try exportfig from FEX: exportfig

include 4 images as different panels in matlab

I am trying to include 4 already present images into one new image, done and created in matlab, like a collage, with 4 images present adjacent to each other, bordering, in the new image. I really do not know where to start. Could you please help me here? In matlab?
Another options if you don't want white space between images is to combine the images into a single matrix.
ie:
image([I1 I2; I3 I4])
of course the images have to be the same size for this to work...
Actually, apart from What Hassan suggested, I was able to achieve my purpose easily using subplot and subimages.
Eg.
subplot(2,2,1)
imshow(I1)
subplot(2,2,2)
imshow(I2)
Thanks for your help :).