How can I insert graphics into existing images?

2 次查看(过去 30 天)
I have images that I would like to add data to, for example, text or smaller images.

采纳的回答

MathWorks Support Team
This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
You can use basic array indexing to insert data into existing images. The following is an example:
% Create and style the text in an axis:
t = text(.05,.1,'Mandrill Face', 'FontSize',12, 'FontWeight','demi');
% Capture the text from the screen:
F = getframe(gca,[10 10 200 200]);
% Close the figure:
close
% Select any plane of the resulting RGB image:
c = F.cdata(:,:,1);
% Note: If you have the Image Processing Toolbox installed,
% you can convert the RGB data from the frame to black or white:
% c = rgb2ind(F.cdata,2);
% Determine where the text was (black is 0):
[i,j] = find(c == 0);
% Read in or load the image that is to contain the text:
load mandrill
% Use the size of that image, plus the row/column locations
% of the text, to determine locations in the new image:
ind = sub2ind(size(X),i,j);
% Index into new image, replacing pixels with white:
X(ind) = uint8(255);
% Display and color the new image:
imagesc(X)
colormap(bone)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by