Re: Get Image resolution?
Posted: Sun Oct 22, 2017 4:48 am
Hi All
Thanks for the solutions.
It is all to do with the image recognition I am playing with at the moment. I have found that using openCV to select a bounding rectangle works great on images with a resolution of 300dpi or greater but a lot of images are scanned at 96 or 100 dpi which creates quite unreliable results. After finding the largest bounding rectangle I autocrop the image so that it only contains image information not borders etc which get in the way.
I need to do this to just over 600,000 images all in .jpg format. These are held in a single folder. My thoughts are to:-
1. Load image
2. Check DPI and reject if too small
3. Autocrop
4. Get and store aspect ration of image
5. Get and store Hash of image
6. Copy image to second folder
Speed is not of the essence as this will run when I am asleep and the next day while I take the wife shopping. Cross platform not so important as the code only needs to be run occassionaly when new images are added. The production of the hash database is the important thing.
PS
One thing I have noticed allready when running some of the code above is that images I grab from say a 1200 X 1200DPI image have their resolution dropped to 96 X 96 DPI. The code I am using to grab the image is here:-
Imagex,Imagey etc are obtained from OpenCV for the largest bounding rectangle. The idea being to grab the portion of the image inside this bounding rectangle to use for the hash. I have not investigated further as yet but would like to maintain the original image DPI.
Thanks to all
CD
Thanks for the solutions.
It is all to do with the image recognition I am playing with at the moment. I have found that using openCV to select a bounding rectangle works great on images with a resolution of 300dpi or greater but a lot of images are scanned at 96 or 100 dpi which creates quite unreliable results. After finding the largest bounding rectangle I autocrop the image so that it only contains image information not borders etc which get in the way.
I need to do this to just over 600,000 images all in .jpg format. These are held in a single folder. My thoughts are to:-
1. Load image
2. Check DPI and reject if too small
3. Autocrop
4. Get and store aspect ration of image
5. Get and store Hash of image
6. Copy image to second folder
Speed is not of the essence as this will run when I am asleep and the next day while I take the wife shopping. Cross platform not so important as the code only needs to be run occassionaly when new images are added. The production of the hash database is the important thing.
PS
One thing I have noticed allready when running some of the code above is that images I grab from say a 1200 X 1200DPI image have their resolution dropped to 96 X 96 DPI. The code I am using to grab the image is here:-
Code: Select all
MyImage = LoadImage(#PB_Any,ImageFile)
GrabImage(MyImage,45,Imagex,Imagey,ImageWidth,ImageHeight)
SaveImage(45,"C:\Temp\" + GetFilePart(ImageFile,#PB_FileSystem_NoExtension) + "_Cropped.jpg")
FreeImage(MyImage)
Thanks to all
CD