Trimming or clipping a character

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.

Answers (1)

Walter Roberson
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

You just directed my attention to here from a question about display some unicode combining characters.
The above approach will not work for unicode combining characters: as we explored in that thread, none of the built-in fonts support those characters, and they all give boxes or question marks or empty.
Potentially you could use a custom font, but even if you did that, the standard representation of combining characters includes dotted areas, and those dotted areas would be written into the image array.
I suggest you consider creating a couple of template matrices with the shapes you want, and corresponding alphadata 0 on the pixels not to be considered, and then you can image() them on top of other images you have of the individual characters. Or if you have images of individual characters, then create combined characters by selectively "and" or "or" the combining characters.
Sort of, but if your purpose is to combine characters visually, then the circles should not be set in the matrix. The circles are representations of position the base characters being modified go in, and are not part of the characters.
Deleting from here and posing as a new question, since this seems to be different query than the main question ...
Walter Roberson wrote: "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."
Can you please illustrate this point using the following image matrix for the character 'H' :
h = [0 1 0 0 0 1 0
0 1 0 0 0 1 0
0 1 0 0 0 1 0
0 1 1 1 1 1 0
0 1 0 0 0 1 0
0 1 0 0 0 1 0
0 1 0 0 0 1 0];
Thanks.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

v k
on 10 Nov 2020

Commented:

v k
on 13 Nov 2020

Community Treasure Hunt

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

Start Hunting!