Discussion:
Embedding imcontrast tool inside a custom Matlab GUI application
(too old to reply)
J.D.
2007-03-02 00:21:00 UTC
Permalink
I am making an image manipulation GUI using Matlab GUIDE. I just
learned about the image processing toolbox's "Modular tools". They
sound great and I wanted to specifically add the image contrast
adjustment tool to my little application. So I added a menu item with
the following callback function:

function imageMenuAdjustContrast_Callback(hObject, eventdata, handles)
imcontrast(handles.displayAxes);

handles.displayAxes is a axis ui object in my main application figure.
And this works great... well almost. When I click the menu item, the
image contrast dialog comes up and I can mess with the controls - and
in real-time the image in handles.displayAxes is modified. However,
when I return to the main window and do other modifications to the
image, the changes imcontrast made seem to have disappeared.

It appeared as if imcontrast was modifying the image "CData" field but
obviously not since its changes seem to vanish when I access that same
data field later in the program.. does anyone have any idea why it
behaves this way? Or am I missing something fundamental?
J.D.
2007-03-02 00:52:20 UTC
Permalink
Just a quick update.. I saw that others suggested using uiwait() on
imcontrast to make the main code wait for imcontrast to return. So in
a little test I modified my menu callback function as follows:

function imageMenuAdjustContrast_Callback(hObject, eventdata, handles)
data = get(handles.displayAxes, 'UserData');
axes(handles.displayAxes); cla;
hImg = imshow(data.imgData);
uiwait( imcontrast(handles.displayAxes) );

data.imgData = get(hImg,'CData');
axes(handles.displayAxes); cla;
hImg = imshow(data.imgData);

(I am keeping the original image data stored in the UserData section
of displayAxes). In this test, the image is visibly modified while the
imcontrast window is open. But once I close it and uiwait() returns,
the image reverts back to its pre-imcontrast form... so what am I
missing here?
J.D.
2007-03-02 15:11:00 UTC
Permalink
(I love these conversations with myself.. hope it helps someone in the
future)

I didn't read the imcontrast help page closely enough. All its doing
is modifying the CLim properties of the axes.. not the actual CData
itself... That is the root of my problem.
MechtEngineer
2014-11-14 05:25:05 UTC
Permalink
Post by J.D.
(I love these conversations with myself.. hope it helps someone in the
future)
I didn't read the imcontrast help page closely enough. All its doing
is modifying the CLim properties of the axes.. not the actual CData
itself... That is the root of my problem.
Hope you don't mind me joining your conversation, but the solution may be found here:
https://groups.google.com/forum/#!topic/comp.soft-sys.matlab/cGToRGLQ_3Y
1. Get the image handle from the figure being adjusted by imcontrast using this:
ImageHandle = findobj(FigureHandle, 'Type', 'image');
2. Get the 'cdata' from the image handle
MechtEngineer
2014-11-14 05:40:12 UTC
Permalink
For example:

img = imread('tire.tif');
figureHandle = figure;
imshow(img);
uiwait(imcontrast(figureHandle));
imageHandle = findobj(figureHandle, 'Type', 'image');
adjustedImg = getimage(imageHandle);
% Check
figure,imshow(adjustedImg);

Loading...