MATLAB Answers

Image from one GUI to another

5 views (last 30 days)
Hi. I am new to MATLAB and Im still learning about GUI. How can I transfer image from one gui to another?
  2 Comments
Ramon Ticzon
Ramon Ticzon on 1 Mar 2019
I used this example code to select the part of the image. How can I transfer both the image and the selected pixels to another GUI so that I can go and proceed to mask the image on the second GUI. Thanks!
imtool close all; % Close all figure windows created by imtool.
baseFileName = 'onion.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
rgbImage = imread(fullFileName);
imshow(rgbImage, []);
axis on;
% Ask user to draw freehand mask.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imrect();
binaryImage = hFH.createMask();
xy = hFH.getPosition;
subplot(2, 2, 1);
imshow(rgbImage, []);
axis on;
drawnow;

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Mar 2019
Edited: Walter Roberson on 1 Mar 2019
  • You can set the Parent property of the containing axes to be the container (such as a figure or uipanel) that the image is to be moved to. It is not well defined whether this will also move any associated colorbar and legend(). It will disappear from the original location. If a colormap has been set for the individual axes, then the colormap will be moved as well, but if the colormap was set against the figure then the colormap will not be moved. Color axes mapping information will be moved (that is, the information about which numeric value in the image is to map to the "first" color, and which numeric value is to map to the "last" color.) This requires that the data has already been created as an image object.
  • You can find the handle of the image and set its Parent property to the axes or hgtransform that the image is to be moved to. It will disappear from the original location. This will not move any associated colorbar or legend. The colormap will not be moved. Color axes mapping information will not be moved. This requires that the data has already been created as an image object.
  • For either of the above two, instead of setting the Parent property, you can copyobj() to the destination container. This would make a duplicate copy: it will not disappear from the original location. It is not well defined whether this would also copy any associated colorbar and legend(). Color axes mapping information would be transferred for the case of copyobj() of the axes, but not for the case of copyobj() of the image object. This requries that the data has already been created as an image object.
  • You can find the handle of the image and get its CData property and find the handle of the place that is to contain the image, and image() or imshow() or imagesc() to the destination. It will not disappear from the original location. Any associated colorbar and legend will not be copied. Any colormap will not be copied. Color axes mapping information will not be transfered. This requires that the data has already been created as an image object.
  • You can save a copy of the data in some convenient place (possibly guidata) and find the handle of the place that is to contain the image, and image() or imshow() or imagesc() to the destination. It will not disappear from any original location. Any associated colorbar and legend wil not be copied. Any colormap will not be copied. Color axes mapping information will not be transfered. This does not require that the data has already been created as an image object. More on sharing data
  1 Comment
Ramon Ticzon
Ramon Ticzon on 1 Mar 2019
Thanks. I'm trying to understand it. An example will be a great help to understand it better. Can u provide some useful codes?

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 1 Mar 2019
See the bottom part of this FAQ entry: Click here for the FAQ
Also see Geoff's answer: Geoff's code

Community Treasure Hunt

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

Start Hunting!