Store a labeled image to be called later by a callback

Hi,
I have this Matlab line:
export_fig(handles.imageAxes, Name, '-jpg');
which I use to save the handles.imagesAxes
As I label things in the handles.imageAxes (using text, regionprops and bwboundaries) the use of setappdata(handles.imageAxes, 'yourVariable', I) does not help.
I decide to use the following lines:
tImage = print2array(handles.imageAxes);
setappdata(handles.imageAxes, 'traceImage', tImage);
Unfortunalty it deos not work as well.
Any idea how can I store a labeled image so it will be called later by another callback?
Thanks.

2 Comments

What kind of labeling are you talking about? Like "connected components labeling" like you'd do with bwlabel() or bwconncom(), or labels like you'd put into the overlay like with text(), plot(), or annotation()?
You do not use regionprops() or bwboundaries() to label anything - that's why I'm confused - though those functions could give you information that you could label the images with, with functions like text(), plot(), etc.
Sorry, I was not clear. You are right the lableing information is based on the regionprops() or bwboundaries() but it is done by the text(), plot().

Sign in to comment.

 Accepted Answer

So what's wrong with export_fig() to save it to the disk file? Maybe try saving as a PNG file instead of JPG so you don't lose any information to bad JPG compression artifacts.

8 Comments

I wish to call it later so saving it and loading it again is not my preferred solution.
I wish to store it in memory and use it in another callback and I cant make setappdata store also the labeling.
This is part of the code I used based on getframe:
I = getimage;
setappdata(handles.imageAxes, 'yourVariable', I);
tI = getframe(handles.imageAxes);
And I get an error on the getframe, any idea why?
Get the cdata field. Try this:
clc;
workspace
img = imread('cameraman.tif');
imshow(img)
hold on;
text(20,20, 'Hello', 'Color', 'r', 'FontSize', 30);
% Extract image, and text, graphics, and anything everything in the overlay
displayedImage = getframe(gca);
% Show extracted image.
figure
imshow(displayedImage.cdata);
This script above works fine but when I add to my GUI the following line:
displayedImage = getframe(gca);
I get a long list of errors:
Error using capturescreen
The rectangle passed to getframe must be at least partially on screen
Error in getframe (line 103)
x=builtin('capturescreen', varargin{:});
Error in TRY3>TOB_Callback (line 340)
displayedImage = getframe(gca);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in TRY3 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)TRY3('TOB_Callback',hObject,eventdata,guidata(hObject))
Any change to know why?
No. Are you using a two screen setup? Is some part of your image on the other monitor, or partially off the screen? Maybe try replacing gca with the handle to your axes, handles.imageAxes.
Thanks. I do work with two screens and if I work on the main screen it works.
I only use one screen and don't know how to get it to work on two screens. You might have to call the Mathworks for that.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!