Could MATLAB do text-mirroring?
9 views (last 30 days)
Show older comments
JUNXIANG ZHANG
on 17 Mar 2021
Commented: Walter Roberson
on 17 Mar 2021
Hi!
I would like to have some inserted text in an image mirrored. An example is shown by the figures below.
Original:
Wanted:
(Note that, this is no string flipping, like 'test' to 'tset')
And preferably NOT through the following work flow:
Cropping -> saving it as a new image -> loading -> flipping.
Much appreciated, thanks.
%% A better example would be:
Original:

Wanted:

The text was added with the function 'insertText'.
Thanks.
0 Comments
Accepted Answer
Walter Roberson
on 17 Mar 2021
Your reference to cropping suggests that you want to do this to parts of images.
Remember that when you crop it is into an array. You can flip the array along the second dimension, and copy the result over the original array locations. There is no need to save to file.
Anything beyond that would be asking whether there is already a built-in function for this purpose. There is no built-in function for this.
Or perhaps you are asking for a built-in function that does ocr to locate text and flip it. There is no built-in function for that purpose.
Or perhaps you are asking for a built-in function that does ocr to locate text, determine what the size and font and symbols are, and synthesize new flipped characters. There is no built-in function for this purpose.
If you have a natural scene such as a photograph that has text overlay, and you want to flip the photograph but also locate and rectify the text so that after the flip of the entire photo, the text will again be readable... there is no built-in function for that. This is also a notably more difficult task, as it requires extrapolation of what was covered by the text to be able to restore the background before writing the new text on to it. For example the original text might happen to be hiding someone's face, and the flipped text might happen to have a space or hallow O in the position that should show the person's face now. This is a challenge to do, and probably requires Deep Learning to automate.
1 Comment
Walter Roberson
on 17 Mar 2021
"The text was added with the function 'insertText'."
In that case insertText into an array just large enough to hold the text, and fliplr the array, and then overwrite part of the image array with the flipped text.
More Answers (1)
KSSV
on 17 Mar 2021
I = imread('image.png') ; % read image
I1 = fliplr(I) ; % flip the image
imshow(I1)
2 Comments
KSSV
on 17 Mar 2021
Edited: KSSV
on 17 Mar 2021
Crop the text part of your image, when prompted.
I = imread('image.png') ;
[I1,rect] = imcrop(I) ; % crop the image where your text is present
%
I1 = fliplr(I1) ;
% Replace
position = round(rect) ;
col1 = position(1);
col2 = col1 + position(3)-1;
row1 = position(2);
row2 = row1 + position(4)-1;
I(row1:row2, col1:col2, :) = I1 ;

See Also
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
