CONVERT TEXT TO IMAGE

조회 수: 10 (최근 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 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