Color relocation in opencv imwrite

I am using OpenCV to resize jpg. The code is similar to

im = cv2.imread(infile)
resized_im = cv2.resize(im, None, None, 0.5, 0.5, cv2.INTER_LINEAR)
cv2.imwrite(outfile, resized_im)

When viewing a modified image, I see that the color has been reduced.

$ identify -verbose input.jpg | grep samp
    jpeg:sampling-factor: 1x1,1x1,1x1
$ identify -verbose resized.jpg | grep samp
    jpeg:sampling-factor: 2x2,1x1,1x1

Is there any way to change this?

Thank!

+3
source share
1 answer

I worked on Android and tried to reproduce your used case in Android CV ... What I did is the following ...

Mat tempMat=new Mat();
Utils.bitmapToMat(bm, tempMat);
Mat tempMat1 = new Mat(tempMat.rows()/2, tempMat.cols()/2, tempMat.type());
Imgproc.resize(tempMat, tempMat1, new Size(), 0.5, 0.5, Imgproc.INTER_LINEAR);
Utils.matToBitmap(tempMat, bm);
bm = Bitmap.createBitmap(tempMat1.width(), tempMat1.height(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(tempMat1, bm);

Then I have code to save both bitmaps to files ... I checked the saved files after downloading them from my Android device to the Ubuntu desktop ...

 atul@ubuntu:~/Development/sdk/platform-tools$ ls -l IMG_?.jpg

    -rw-r--r-- 1 atul atul 209336 Feb 13 09:58 IMG_1.jpg
    -rw-r--r-- 1 atul atul  63237 Feb 13 09:58 IMG_2.jpg
 atul@ubuntu:~/Development/sdk/platform-tools$ identify -verbose IMG_1.jpg | grep samp
        jpeg:sampling-factor: 2x2,1x1,1x1
 atul@ubuntu:~/Development/sdk/platform-tools$ identify -verbose IMG_2.jpg | grep samp
        jpeg:sampling-factor: 2x2,1x1,1x1

- () Destination Mat . , ...

, , , Chroma, Lumina ... YCrCb, Lumina, - Chroma Red, - Chroma blue...

OpenCV Y Cr Cb. ...

http://docs.opencv.org/doc/tutorials/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.html

, CV CV CV CV CV Python - , CV CV...

, ...

+1
source

All Articles