How can I insert graphics into existing images?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have images that I would like to add data to, for example, text or smaller images.
Akzeptierte Antwort
MathWorks Support Team
am 27 Jun. 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)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!