Reshowing an image in a programmatic gui

Hi,
I have programmed a gui in which I use hImage = imshow(image) to show a binary image. Then I add some stuff to the image handle like scrollpanels and magnification box etc. I then make changes to the image itself (remove stains by changing some areas into ones (white)).
How can I show the image again in the same gui by replacing the old image with the new, edited image?
Using imshow(image) causes a long error log because of handle errors. Redefining hImage = imshow(new_image) along with all other functionalities (scrollpanels etc.) also causes errors.
-Ville

2 件のコメント

Sean de Wolski
Sean de Wolski 2011 年 7 月 7 日
Perhaps you could include some code. Are you using GUIDE?
Take a look at the axes command to get control of the axes directly.
Ville
Ville 2011 年 7 月 8 日
No, I'm not using GUIDE. Here's the code I use in the beginning to show my image and add those scrollpanels etc.
handles.hImage = imshow(handles.opened_ecg_file); % Show the image
% Set image hittest to 'on' so that it will react to mouse button presses
set(handles.hImage, 'HitTest', 'on', 'ButtonDownFcn', @button_down_fcn);
% Create scroll panels
handles.hScrollPanel = imscrollpanel(handles.fig, handles.hImage);
set(handles.hScrollPanel, 'Units', 'normalized','Position', [0 .1 1 .9]);
% Create magnification box
handles.hMagBox = immagbox(handles.fig, handles.hImage);
%pos = get(handles.hMagBox, 'Position');
set(handles.hMagBox, 'Position', [510, 25, 70, 25]); % Position the box
handles.hCoords = impixelinfo(handles.fig, handles.hImage); % coords box
Now, if I edit the image and try to replace the old image with the new one, I get a lot of errors.

サインインしてコメントする。

回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 7 月 8 日

0 投票

Everytime you use imshow you must also give that image the tools, example:
handles.fig=figure
handles.ax=axes
handles.hImage = imshow('trees.tif'); % Show the image
% Set image hittest to 'on' so that it will react to mouse button presses
set(handles.hImage, 'HitTest', 'on', 'ButtonDownFcn', @button_down_fcn);
% Create scroll panels
handles.hScrollPanel = imscrollpanel(handles.fig, handles.hImage);
set(handles.hScrollPanel, 'Units', 'normalized','Position', [0 .1 1 .9]);
% Create magnification box
handles.hMagBox = immagbox(handles.fig, handles.hImage);
%pos = get(handles.hMagBox, 'Position');
set(handles.hMagBox, 'Position', [510, 25, 70, 25]); % Position the box
handles.hCoords = impixelinfo(handles.fig, handles.hImage); % coords box
pause(2)
handles.hImage = imshow('cameraman.tif'); % Show the image
% Set image hittest to 'on' so that it will react to mouse button presses
set(handles.hImage, 'HitTest', 'on', 'ButtonDownFcn', @button_down_fcn);
% Create scroll panels
handles.hScrollPanel = imscrollpanel(handles.fig, handles.hImage);
set(handles.hScrollPanel, 'Units', 'normalized','Position', [0 .1 1 .9]);
% Create magnification box
handles.hMagBox = immagbox(handles.fig, handles.hImage);
%pos = get(handles.hMagBox, 'Position');
set(handles.hMagBox, 'Position', [510, 25, 70, 25]); % Position the box
handles.hCoords = impixelinfo(handles.fig, handles.hImage); % coords box

5 件のコメント

Ville
Ville 2011 年 7 月 8 日
I have tried that too but I still get the errors.
Sean de Wolski
Sean de Wolski 2011 年 7 月 8 日
What errors? Be specific. If you run Paulo's code does it work?
Ville
Ville 2011 年 7 月 11 日
Yes, Paulo's code runs if I run it as a separate program but I can't make my own code work the same way.
The error is:
??? Error using ==> get
Invalid handle object.
Error in ==> imscrollpanel>getVisibleImageRect at 568
xdata = get(hIm,'XData');
Error in ==> impixelinfoval>isCursorOutsideVisibleImage at 208
rect = api.getVisibleImageRect();
Error in ==> impixelinfoval>displayPixelInfo at 117
if isempty(him) || isCursorOutsideVisibleImage(him,x,y)
Error in ==> iptaddcallback>callbackProcessor at 146
fun(varargin{:});
??? Error using ==> waitfor
Error while evaluating figure WindowButtonMotionFcn
It repeats that same error multiple times on each run.
Ville
Ville 2011 年 7 月 13 日
Deleting the old handles and redefining them afterwards seems to do the trick.
Image Analyst
Image Analyst 2011 年 7 月 13 日
MATLAB is case sensitive. So your "hIm" and "him" are different variables.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

質問済み:

2011 年 7 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by