CONVERT TEXT TO IMAGE

62 vues (au cours des 30 derniers jours)
muath shaikh
muath shaikh le 24 Déc 2014
Modifié(e) : DGM le 29 Mar 2024
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

Réponse acceptée

Image Analyst
Image Analyst le 24 Déc 2014
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 commentaires
muath shaikh
muath shaikh le 24 Déc 2014
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 le 24 Déc 2014
text(x,y, 'Hello World');
export_fig(filename, gca);

Connectez-vous pour commenter.

Plus de réponses (2)

Sean de Wolski
Sean de Wolski le 24 Déc 2014
Modifié(e) : Sean de Wolski le 24 Déc 2014
>> imshow(insertText(zeros(200,700),[100 100],'Hello World','BoxOpacity',0,'FontSize',50,'TextColor','r'))
Computer Vision System Toolbox required.
  4 commentaires
Wenjie Wu
Wenjie Wu le 28 Mar 2024
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 le 29 Mar 2024
Do what it says "Contact your License Administrator to review the Options File." or else call tech support for installation help.

Connectez-vous pour commenter.


DGM
DGM le 29 Mar 2024
Modifié(e) : DGM le 29 Mar 2024
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 commentaire
DGM
DGM le 29 Mar 2024
Modifié(e) : DGM le 29 Mar 2024
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.

Connectez-vous pour commenter.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by