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
2009 年 6 月 27 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!