I've already asked this question I did not get satisfactory answers, So I did more research and I'm putting this question forward in a better way. I read an image through OpenCV``imread
method. And I saved it using imwrite
method. It increases the output file size by more than double.
Below are the details of the images which I obtained from imagemagick (I did not write all the details down, I'm attaching the images for all the details are needed):
Input Image:
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1836x3264+0+0
Resolution: 72x72
Print size: 25.5x45.3333
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 5992704
Compression: JPEG
Quality: 75
Filesize: 267KB
Number pixels: 5.993M
Output Image:
- Format: JPEG (Joint Photographic Experts Group JFIF format)
- Mime type: image/jpeg
- Class: DirectClass
- Geometry: 1836x3264+0+0
- Units: Undefined
- Type: TrueColor
- Endianess: Undefined
- Colorspace: sRGB
- Depth: 8-bit
- Channel depth: red: 8-bit green: 8-bit blue: 8-bit
- Channel statistics:
Pixels: 5992704 - Compression: JPEG
- Quality: 95
- Filesize: 611KB
- Number pixels: 5.993M
As you can see, the input image size is 267KB but the output image size turned out to be 611KB. Now I know that its size depends on the encoder, Compression value, bit-rate etc.
I want to know is there anyway I can save the image in the exact same size of the input image.
I also tried using the compression in openCV
like this
cv2.imwrite('result.jpg', image, [int(cv2.IMWRITE_JPEG_QUALITY), 45])
.
Here the image quality would be 45, but the image size would still be greater than the input image (around 300KB).
I don't want to go less than 45 because it would affect the image details and loss of data.
I tried using external libraries like scipy, matplotlib. But they all bump the image size regardless.
Any clue on why the output image increase and how we can fix it is very much appreciated.
Here is some code for reference
import cv2 #opencv library for image processing implementations
def main():
im = cv2.imread('sample.jpg')
cv2.imwrite('result.jpg', im)
if __name__=='__main__':
main()
And here is the image for reference.