CONVERT TEXT TO IMAGE

62 ビュー (過去 30 日間)
muath shaikh
muath shaikh 2014 年 12 月 24 日
編集済み: DGM 2024 年 3 月 29 日
Dear Colleagues, I wanna convert text into small image JPG image,like Name :'Roburt'; But i wanna to be smallest image like 2 * 7 for example, no need to be large

採用された回答

Image Analyst
Image Analyst 2014 年 12 月 24 日
If you don't have the Computer Vision System Toolbox you can use text() and then save the axes with export_fig (Available from the File Exchange).
  2 件のコメント
muath shaikh
muath shaikh 2014 年 12 月 24 日
Actually i dont have Computer vision system toolbox Could you explain your idea by example, and how to save as image
Image Analyst
Image Analyst 2014 年 12 月 24 日
text(x,y, 'Hello World');
export_fig(filename, gca);

サインインしてコメントする。

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2014 年 12 月 24 日
編集済み: Sean de Wolski 2014 年 12 月 24 日
>> imshow(insertText(zeros(200,700),[100 100],'Hello World','BoxOpacity',0,'FontSize',50,'TextColor','r'))
Computer Vision System Toolbox required.
  4 件のコメント
Wenjie Wu
Wenjie Wu 2024 年 3 月 28 日
Hello,
I have the 'Computer Vision System Toolbox' installed/licensed, on 2023b.
But when I run the insertText function, it returns:
License checkout failed.
License Manager Error -39
User/host not on INCLUDE list for Video_and_Image_Blockset.
Contact your License Administrator to review the Options File.
Troubleshoot this issue by visiting:
https://www.mathworks.com/support/lme/39
Diagnostic Information:
Feature: Video_and_Image_Blockset
License path: xxx
Licensing error: -39,147.
Image Analyst
Image Analyst 2024 年 3 月 29 日
Do what it says "Contact your License Administrator to review the Options File." or else call tech support for installation help.

サインインしてコメントする。


DGM
DGM 2024 年 3 月 29 日
編集済み: DGM 2024 年 3 月 29 日
Old question, but let's approach this from the specifics of the original use case. We want a small image of some text. Trying to use CVT insertText() or figure capture are going to both be severely limited in creating compact text images. MIMT textim() can generate images of text, and is generally built around a focus on compactness. All fonts are bitmapped and fixed-width.
The most compact alphanumeric font has 8x5px characters.
mytext = 'robbybobbybertyboi';
textpict = textim(mytext,'everex-me');
The most compact hexadecimal-only human-readable font has 5x4px characters.
mytext = '0123456789 ABCDEF';
textpict = textim(mytext,'micronum');
Bear in mind that those images have one pixel of padding on two edges, so you technically could trim those off as well. MIMT textim() also has convenient 2x2 hexadecimal-only fonts, but they're not intended to be human-readable. Those are the sacrifices made for compactness.
That aside, you're not going to find any fonts in any tools that will allow you to fit 6 human-readable letters into a 2px x 7px image.
If your goal is to create images with small features like this, then using JPG is unacceptable. Do not use JPG unless you like ruining your images and making them take up more disk space for no good reason.
For other text-to-image needs, see:
... at least that's what I have in my notes.
  1 件のコメント
DGM
DGM 2024 年 3 月 29 日
編集済み: DGM 2024 年 3 月 29 日
FWIW, this is what you get when you try to use AA scalable fonts and lossy workflows for small text images.
mytext = 'robbybobbybertyboi';
sz = [8 90]; % try to cram the text into the same space used by textim()
mybg = zeros(sz);
textpict = insertText(mybg,fliplr(sz/2),mytext,'anchorpoint','center', ...
'BoxOpacity',0,'FontSize',8,'TextColor','w');
% now let's save it as a JPG and read it back
imwrite(textpict,'trash.jpg')
textpict = imread('trash.jpg');
% the image is too small to actually see on the forum,
% so let's scale it for sake of inspection
textpict = imresize(textpict,10,'nearest');
imshow(textpict,'border','tight')
Yeah, that's trash.
% use figure capture
mytext = 'robbybobbybertyboi';
ht = text(0,0,mytext);
ht.FontSize = 5; % try to replicate the same image size as textim()
ht.VerticalAlignment = 'bottom';
ht.Units = 'pixels';
hax = gca;
hax.Units = 'pixels';
hax.Position(3:4) = ht.Extent(3:4);
textpict = export_fig(gca); % capture the axes
textpict = 255-textpict; % invert it so it matches other examples
% now let's save it as a JPG and read it back
imwrite(textpict,'trash.jpg')
textpict = imread('trash.jpg');
% the image is too small to actually see on the forum,
% so let's scale it for sake of inspection
textpict = imresize(textpict,10,'nearest');
imshow(textpict,'border','tight')
... and that's even worse.
For the given task, neither are nearly as simple to use, especially if you expect to be able to get consistently predictable image sizes.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by