MATLAB Answers

Image Saving to Variable in Workspace (NOT imwrite)

5 views (last 30 days)
Hi everyone,
From a computational time point of view, I'm trying to save an image into the workspace instead of creating a figure and grabbing the image. I'm performing a very important task in a very short amount of time 10 sec, and have to perform this task repetitively.
Therefore saving the image using imwrite() is not acceptable due to the computational requirement of having to save the image in memory, and retrieving it. Attached is a code and an image of the figure I am creating as well. Instead of using imshow() in a figure, how can I save the image directly (LLLL).
CODE BEING USED:
figure('Name','Posible Brightness spots for quad-tree analysis');
imshow(sp_possible_quadtree, []);
axis image;
title('Potential blobs for croppping and performing quadtree', 'FontSize', captionFontSize);
LLLL = getimage;
OUTPUT OF THE CODE in a Figure:
then this is the image that is grabbed from the figure and saved.
------------------------------------------------------------------------------------------------------------
Instead of the code above, an ideal solution would be something like this or anything close that doesn't requiere to create an external window (figure handler) to grab it from there.
LLLL = ideal_unknown_function(sp_possible_quadtree, []);
Thanks for your help in advance.

  3 Comments

Subhadeep Koley
Subhadeep Koley on 14 Feb 2020
@ Daniel Posada your variable sp_possible_quadtree is already saved in the workspace right? Otherwise how you are displaying it using imshow() ?
Stephen Cobeldick
Stephen Cobeldick on 14 Feb 2020
imshow shows an array of data in some axes whereas getimage returns an array of data from some axes, so what difference/s do you expect between sp_possible_quadtree and LLLL ?
Daniel Posada
Daniel Posada on 14 Feb 2020
@Subhadeep Koley That is correct I do have sp_possible_quadtree in the workspace, the problem is that by itself it won't show up the features, unless I add the input []*. But what I want to do is to save it without having to go through the imshow process. I don't want to display it, I just want to have it saved in a variable in the workspace.
*(imshow uses [min(I(:)) max(I(:))] as the display range, if [] option is selected)
@Stephen Cobeldick What I want to do is save that image directly without having to use imshow in a figure in order to get the image but still be able to have theb blobs on it as well. If I plot only sp_possible_quadtree the image will be completely black, because it's not showing the features, whereas the LLLL does show them (attached image), but I have to go throught the whole figure process and imshow in order to obtain it. In this case sp_possible_quadtree is a double. where the contents are either 0 for Black, or an integer 1, 2, 3, 4, ... n to differentiate the different blobs. It comes from a bwlabel in order to separate those zones.
sp_possible_quadtree = bwlabel(keeperBlobsImage, 8);

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 14 Feb 2020
Use rescale, you can also specify the lower and upper range of scaling.
LLLL = rescale(sp_possible_quadtree);

  2 Comments

Walter Roberson
Walter Roberson on 14 Feb 2020
In older MATLAB releases use mat2gray (which is misleadingly named)
Daniel Posada
Daniel Posada on 14 Feb 2020
tested both methods and they worked perfectly, thank you very much to both of you.

Sign in to comment.

More Answers (1)

Stephen Cobeldick
Stephen Cobeldick on 14 Feb 2020
Edited: Stephen Cobeldick on 14 Feb 2020
"In this case sp_possible_quadtree is a double. where the contents are either 0 for Black, or an integer 1, 2, 3, 4, ... n"
LLLL = sp_possible_quadtree ./ n
Images stored as floating point are assumed to be scaled from 0 to 1, so you just need to rescale your image.

  1 Comment

Daniel Posada
Daniel Posada on 14 Feb 2020
Stephen this aproach works as well, thank you very much.

Sign in to comment.

Sign in to answer this question.