alternative approach of "insertObjectAnnotation" function

38 Ansichten (letzte 30 Tage)
Yu Li
Yu Li am 9 Sep. 2025 um 0:53
Kommentiert: Yu Li am 9 Sep. 2025 um 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

Akzeptierte Antwort

cui,xingxing
cui,xingxing am 9 Sep. 2025 um 1:37
Bearbeitet: cui,xingxing am 9 Sep. 2025 um 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 Kommentare
Yu Li
Yu Li am 9 Sep. 2025 um 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 am 9 Sep. 2025 um 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).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 9 Sep. 2025 um 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 Kommentar
Yu Li
Yu Li am 9 Sep. 2025 um 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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by