text image in matlab without using getframe

조회 수: 3 (최근 30일)
Patrik Ek
Patrik Ek 2014년 2월 3일
답변: DGM 2024년 10월 20일
Hi, I would like to create a text image in matlab, so to say write a text and save it as an image. I have already managed to implement this by the following steps,
1) Creating a new figure and create an image in the figure.
2) Type in some text using the "text" function.
3) Since text only creates text in one pixel (the text looks larger, though the text data is only located in one pixel. The scaling is external and not a part of the image), I use getframe to take a screenshot of the frame.
4) Close the figure and extract frame data from the output of getframe.
5) Extract the desired part of the frame and discards the rest, create a new figure with desired data and save it.
The method works fine except for in step 3). The problem is that get frame takes a screenshot of the current axis. This makes the whole method unstable since the a screenshot only captures what is on the screen. If I do other work on the computer on the same time, this may appear in the image instead of the expected text. I do not have the "Computer Vision System Toolbox" so I cannot use insertText. Are there any other ways to do this that does not require getframe?
Thankful for answer, Patrik
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 2월 3일
I believe there is a File Exchange contribution that can do this.

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2024년 10월 20일
See:
The accepted answer has unnecessary flaws, but I give an attempt to improve upon it. I don't think figure capture is even remotely elegant, and it takes some effort to make sure the capture process doesn't cause the image to be resized/padded/distorted.
That answer also covers text insertion by basic composition and it reviews multiple user-submitted File Exchange submissions, which all have varied functionality.
There is also insertText(), but that requires CVT.

Community Treasure Hunt

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

Start Hunting!

Translated by