Saving a generated image on Matlab Gui - matlab-figure

I am trying to save an image that I generated on a Matlab Gui. I tried following code with a push button:
[Save,savename] = uiputfile('*.bmp','Save Figure As...')
fname=fullfile(savename,Save);
imwrite(handles.axes2, 'fname', 'bmp');
It doesn't work. Can anyone please help?

imwrite is for saving image data (as a matrix) to an image file. If you want to save the figure, you will want to use saveas.
If you need to save an image of a specific axes, you can use getframe to save a screenshot of the specified axes, then convert this to an image using frame2im and then use imwrite to save this image data to a file.
frame = getframe(handles.axes2);
im = frame2im(frame);
imwrite(im, fname)

Related

How do we load and resize image using tensorflow?

I have just downloaded the dataset caltech101 and I want to resize the image into the shape of (200,300,3). As I have read, I first need to convert the image into a tensor and then resize it using tf.image.decode_jpeg. But I don't know how to start from scratch with an image and turn it to a tensor.
(I'm a beginner in learning machine learning)
To load an image using TensorFlow, first decode it like so:
image = tf.image.decode_jpeg(...)
To resize it, use the image from the code above, like so:
resized_image = tf.image.resize_images(image, [299, 299])
You can find more on their API documents here.

How to save image with graphics object (lines ) in Matlab?

I need to save an image with lines on it.
But I can't achieve save image with lines on it.
I displayed image with lines and text (I use insertText()).
I saved only image and text.
Could anyone help me ?
Idisp = getimage(gca);
imwrite(Idisp, 'test.png');
I would appreciate any help.

How to convert RGB image to Luminance image and store the image as .raw file in Matlab

i am trying to convert an RGB image to a Luminance image and save it as a .raw image to use it in another software. I am using the following code
m = imread('20x20-alpha1-1.jpg');
out = zeros(1942,2588);
for i=1:1942
for j=1:2588
out(i,j) = 0.2126*m(i,j,1) + 0.7152*m(i,j,2) + 0.0722*m(i,j,3);
end
end
fileID = fopen('20x20-alpha1-1.raw');
fwrite(fileID,out);
fclose(fileID);
However, when I try to open the image with IrfanViewer, the file is said to be corrupted. Is it a problem in my code ? If so how can I convert this image to Luminance image and save it ?
Thank you :)
There is no need to mess around with .raw files in this case. Write a tiff file instead:
imwrite(out,'20x20-alpha1-1.tiff','tiff')

Emgu.CV load grayscale float32 image as <Bgra, Single>

I am trying to load a small TIFF image using Emgu.CV (2.4.10). The image is a 32bit (float32) single band image, but when loading it using Emgu it opens it as a <Bgra, Single> image.
Is Emgu misinterpreting the image or are there some method to force Emgu to load the image as a <Gray, Single>?
I assume you are trying to read a image from a file. If this is the case you can simply specify the image format and bit depth when declaring the Image.
Image<Gray,Single> myImage = new Image<Gray,Single>("myFile.tiff");

Save output image in matlab window to image

I have a image and some contours as bellow figure. I want to save the output into image (png or jpg). The saved image only contains the image region without the matlab window. Let see my example in the figure. Could you have me implement it by matlab? This is my code to make output figure
img = imread('coins.png');
mask_red=zeros(size(img));
mask_green=zeros(size(img));
mask_red(30:160,40:170)=1;
mask_green(70:100,60:130)=1;
imagesc(uint8(img),[0 255]),colormap(gray),axis off;axis equal,
hold on;
[c1,h1] = contour(mask_red,[0 0],'r','Linewidth',3);
[c2,h2] = contour(mask_green,[0 0],'g','Linewidth',3);
hold off;
%% Save output figure
Use the getframe and cdata idiom. If the figure is open, simply do this:
f = getframe;
im = f.cdata;
im will contain the image that was contained inside your frame as a RGB image. Running your code in your post, then the above code, then doing imshow(im), we get:
If you want to save the image, just use imwrite:
imwrite(im, 'coins_final.png');
The image will be saved in a file called coins_final.png.

Resources