How to reverse image without changing the resolution

Hi, I used the function fliplr to reverse an image with 300ppp but the image in output is with 72ppp. I want to reverse the image without changing the resolution. The code used is: I = imread(filename); B=fliplr(I); imwrite(B,...);

Risposte (2)

You need to learn a bit more about resolution and particularly understand that it's mostly meaningless and is only a hint to a program when it prints the image onto paper.
Matlab does not let you set the resolution of images when saved to disk (because it is pointless). Whether you say that the resolution is 300ppp, 72ppp or 1500000ppp, the exact same image is saved. That resolution is just saved as a single number alongside the image.
If your image was scanned at 300ppp, then it is still 300ppp after you've flipped it and saved it.

9 Commenti

The image was scanned at 300ppp and saved at 72ppp.
Guillaume
Guillaume il 29 Gen 2018
Modificato: Guillaume il 29 Gen 2018
Again, that number is meaningless. You could open the image file with a hex editor, change the 72 back to 300 or 1500000 or whatever you want, without making a iota of difference to the image itself.
The number is saved alongside the image. Change its value makes absolutely no difference to the image itself. The image size is the important parameter. This has not changed when you processed the image in matlab.
If it bothers you so much that it doesn't say 300 when you look at the properties of the image in whichever image viewer you're using, just change it in that viewer (assuming it lets you).
Any decent image viewer/processing software lets you ignore the dpi anyway since it's meaningless.
And by the way, which image format are you using? Because the majority of them don't even store the resolution.
Then you can use the Resolution tag of a Tiff object to set the resolution to whatever you want:
img = imread(filename);
flippedimg = fliplr(img);
tiffobj = Tiff('c:\somewhere\somefile.tif', 'w');
tiffobj.setTag('ResolutionUnit', Tiff.ResolutionUnit.Inch);
tiffobj.setTag('XResolution', 300);
tiffobj.setTag('YResolution', 300);
tiffobj.write(flippedimg);
tiffobj.close;
But again, setting the resolution makes zero difference to the image, is only useful if you intend to print the image to tell the printer what area of the paper the image should cover, can be overriden by any software, and is usually ignored.
If you're only viewing the image on screen the resolution is meaningless.
The resolution is important because I'm going to do a text recognition from the image
I have this error: Error using tifflib Unable to retrieve ImageLength.
Error in Tiff/writeAllStrips (line 1908) meta = tifflib('retrieveMetadata', obj.FileID);
Error in Tiff/write (line 1459) obj.writeAllStrips(varargin{:});
Text recognition does not depend on the resolution. For example,
Does your ability to OCR those letters depend upon how far away the skywriting is?
We're going back to my initial statement: "You need to learn a bit more about resolution and particularly understand that it's mostly meaningless."
See this or this for example.
The only important value is the size of the image in pixels. This has not changed. The resolution in ppi or whatever is completely irrelevant. It's just a statement, the same way that I could show you a photo and tell you that photo is at 300 ppi, then show you the same photo and tell you it's at 72 dpi. It's still the same photo.
For image processing, including OCR, what you call resolution is completely irrelevant and not used for anything.

Accedi per commentare.

Resolution is a tag in the image, with the specific tag mechanism depending on the image format. There are no routines provided for writing JPEG or PNG tags, but see https://www.mathworks.com/matlabcentral/answers/349701-overwrite-an-image-with-new-imfinfo-data#answer_275016

2 Commenti

Also note that with Tiff class, you can have it modify the content of a Tiff image, leaving the tags intact.

Accedi per commentare.

Categorie

Scopri di più su Images in Centro assistenza e File Exchange

Richiesto:

il 29 Gen 2018

Commentato:

il 30 Gen 2018

Community Treasure Hunt

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

Start Hunting!

Translated by