In MATLAB, how to annotate a figure with an image?
I'd like to overlay an image on top of my figure at a specific point.. e.g. I want "cherry.png" [24px X 24px] drawn at the normalized point [0.20, 0.50] of a 600px X 600px figure. I have access to the Image Processing toolbox, and I'm aware of "imrea开发者_如何学编程d()", however it is unclear to me how to overlay at a specific point. Any ideas/references that I should check out?
If you want your 24-by-24 pixel image to be centered at the normalized point (0.2,0.5)
(equivalent to (120,300)
in pixels), then you can create an axes object that is 24-by-24 pixels and centered at your point and add an image to the axes with the IMAGE function. For example:
img = imread('cherry.png'); %# Read the data from your image file
hFigure = figure('Position',[100 100 600 600]); %# Make the figure window
hAxes = axes('Parent',hFigure,... %# Add the axes to the figure
'Units','pixels',... %# with units of pixels
'Position',[108 288 24 24]); %# so the position is easy to define
hImage = image(img,'Parent',hAxes); %# Plot the image
set(hAxes,'Visible','off'); %# Turn the axes visibility off
Note that when I loaded the image data using IMREAD I assumed it was a 3-D RGB image. If it's an indexed image you'll have to get the additional color map output from IMREAD so you can convert the indexed image to an RGB image.
精彩评论