How can I insert graphics into existing images?

2 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 27 Juin 2009
I have images that I would like to add data to, for example, text or smaller images.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 27 Juin 2009
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)

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by