Clear Filters
Clear Filters

How to substitute "getimage" function?

3 views (last 30 days)
I don't have a the Image Toolbox installed in my pc in my new company and I would like to know how to substitute the getimage function for now:
function addchippicture_button_callback(hObject, eventdata, handles)
global dataStruct
[FileName,PathName] = uigetfile('*.png');
chip_image = strcat(PathName,FileName);
chip_image = imread(chip_image);
image('Parent', handles.chip_axes, 'CData', flipdim(chip_image,1));
axis(handles.chip_axes,'tight');
dataStruct.chip_image = flipdim(getimage(handles.chip_axes),1);
end
Thank you very much!

Accepted Answer

Alex Taylor
Alex Taylor on 26 Aug 2013
Edited: Alex Taylor on 26 Aug 2013
The point of the previous comments is that the 'CData' property of the HG image object is what you want to query. The use of things like imshow was just to demonstrate an example. Here is a non-IPT specific example:
hFig = figure;
hIm = imagesc(rand(200,200));
im = get(hIm,'CData');
Or, if you only have an axes handle in your particular scope:
hIm = findobj(handles.chip_axes,'type','image');
im = get(hIm,'CData');
  3 Comments
Image Analyst
Image Analyst on 26 Aug 2013
Edited: Image Analyst on 26 Aug 2013
That's the same thing I told you and you said it didn't work. Anyway if you use imagesc(), it applies some kind of funky colormap for gray scale images by default that's usually not what you want (Alex, why is that?) so you might also want to apply the desired colormap, such as gray(256), to get rid of it otherwise I think it will be applied to the image you extract from the axes.
Alex Taylor
Alex Taylor on 27 Aug 2013
The default colormap of the figure is jet, which is what you get when you call imagesc. You are free to set the colormap property of the HG figure to whatever you want. In imshow, we set the colormap to a grayscale colormap.
The 'CData' property of the image object is completely independent of the colormap property of the Figure. The 'CData' defines a set of indices, the 'Colormap' of the figure defines how those indices will be resolved into colors:
h_fig = figure;
h_im = imagesc([1 2; 3 4]);
get(h_im,'cdata')
hfig = figure('colormap',gray(4));
h_im = imagesc([1 2; 3 4]);
get(h_im,'cdata')

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 26 Aug 2013
Get the CData property. Try
h = image(......
get(h,'CData')
or maybe this is what you want
dataStruct.chip_image = flipud(chip_image);
  2 Comments
André
André on 26 Aug 2013
Thank you for the fast reply.
But it didn't work. I still cannot take the data from the axes without "getimage".
Image Analyst
Image Analyst on 26 Aug 2013
I think you did something wrong. Show your code. Why do you want the display data anyway, instead of the actual original data? This seems to be a dangerous thing to do and I would not recommend it at all. The displayed data could be changed in ways that you are not aware of. I think you'd be better off using the original data you got from imread().

Sign in to comment.


Wayne King
Wayne King on 26 Aug 2013
Try
get(h,'CData')
on the graphics handle.
For example:
I = imread('cameraman.tif');
h = imshow(I);
A = get(h,'CData');
isequal(I,A)
figure;
imshow(A)
  2 Comments
André
André on 26 Aug 2013
Thank you for the fast reply.
imshow() is part of the Image Toolbox so I don't have it. =/
Walter Roberson
Walter Roberson on 26 Aug 2013
image(A) instead of imshow(A)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!