alternative approach of "insertObjectAnnotation" function

조회 수: 38 (최근 30일)
Yu Li
Yu Li 2025년 9월 9일 0:53
댓글: Yu Li 2025년 9월 9일 12:41
Hi:
I'm doing some stock analysis, I use Matlab to plot 4 different figures and connect them together. then I would like to add a customized description.
I found in order to add the text on an image I need to buy computer vision toolbox... so come here to ask if there is any alternative approach to add cusotmized text in the figure attached.
Thanks!
Yu

채택된 답변

cui,xingxing
cui,xingxing 2025년 9월 9일 1:37
편집: cui,xingxing 2025년 9월 9일 1:49
You can use the title built-in function(only require MATLAB) to set a custom title — it is designed for graphics objects — instead of using insertObjectAnnotation, which directly adds a text-shaped annotation onto the image and returns the resulting RGB image array.
Additionally, if you want to customize the title position, you can also try the text built-in function(only require MATLAB) to place a custom title at specified coordinates.
Example:
figure;
t = tiledlayout(2,2);
% Tile 1
nexttile
plot(rand(1,20))
title('Your Title 1')
% Tile 2
nexttile
plot(rand(1,20))
title('Your Title 2')
% Tile 3
nexttile
plot(rand(1,20))
title('Your Title 3')
% Tile 4
nexttile
plot(rand(1,20))
title('Your Title 4')
title(t,"customized text here",FontSize=20,FontWeight="bold")
  댓글 수: 2
Yu Li
Yu Li 2025년 9월 9일 3:03
Hi:
thanks for your detail reply. I do not want use the subplot format as the control of white space between different axis does not meet my requirement. this is why I generate each figure and connect them.
I trid "text" function and found it is the best, the x, y is based on the pixel of a figure so it is easier to control. thank you.
Yu
cui,xingxing
cui,xingxing 2025년 9월 9일 3:23
Do not use subplot; it is an outdated function. Please use tiledlayout instead — it lets you control the spacing between different axes(TileSpacing).

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2025년 9월 9일 5:00
insertObjectAnnotation from the Computer Vision Toolbox is used to insert text into an array, retaining full resolution of the array. The resulting array is suitable for writing out at full resolution to file using imwrite() or similar. There is no need to display the image at any point when using this function.
You can also choose to display the image and use functions such as title() and text(). These work well if your final destination is the displayed image.
However, if your final destination is writing to an image file, then using functions such as title() and text() requires that you capture plotted information using getframe . getframe() works at whatever resolution the axes were displayed at, which is typically either larger or smaller than the original image resolution. getframe() is not suited at all for retaining the original image resolution.
If you need to retain the original image resolution, then the tools of the Computer Vision Toolbox are the only supported functions.
  댓글 수: 1
Yu Li
Yu Li 2025년 9월 9일 12:41
Hi Walter:
yes you are correct. my current workflow is:
1. plot & print to RGBimage 4 figures separately
2. connect them into 1 image
3. imshow
4. add text
5. print
step 5 needs to specify the resolution, i.e. it is hard to control the resolution to be the same like original image. but as my purpose is to find an alternative approach of insertObjectAnnotation function, it is good enough for me now.
Thanks!
Yu

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

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by