Trimming or clipping a character
2 views (last 30 days)
Show older comments
Hello,
If there is just one character in a text string, and I want to clip it (trim it) so that only 50 to 75 % of it is displayed (starting from the left), then how to go about it? The remaining 25 to 50 % of the character (from the right) must be hidden from the view. For example, if this trimming operation T is applied to small 'd', then it would take away the vertical bar and some portion of the resultant c, and give a small semi-circle from pi/2 to 3*pi/2.
Thanks.
0 Comments
Answers (1)
Walter Roberson
on 10 Nov 2020
Use the Computer Vision toolbox insertText() function to draw the character into an array with your desired size and font and color.
Then you can take the resulting image array and extract portions of it, either using imcrop() or with just plain indexing. Then image() the clipped array onto the display, providing XData and YData parameters to image() so that it knows where (in data units) to draw the clipped array.
Instead of cropping the array, another approach would be to use an AlphaData parameter to image(), setting the AlphaData to 1 for pixels intended to be visible, and to 0 for pixels intended to be invisible. That approach would be preferred if you are moving the character on the display and wanting to update which portions are visible as you go, as you could achieve that by changing the XData and YData and AlphaData properties without having to clip each time.
Or if you are wanting to get the effect that the letter is under an opaque object, then do not bother with the alpha data: just use XData and YData to move it, and make sure that you have uistack to put it "under" the object that might be blocking it.
Caution: if you are wanting to do this kind of work in 3D then you would have the problem that image() objects are 2D and nearly disappear as soon as you rotate the view. To get around that problem, instead of using image() to display the array, use a surface with the array as the CData with texture-mapping mode turned on; typically it is easier to just use warp() to take care of the setup.
4 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!