0

I consider whether it will have any matter if I am passing to IplImage *input image in BGRA format, or RGBA format in order to make its resizing using available interpolation algorithms:

NTER_NEAREST - a nearest-neighbor interpolation
INTER_LINEAR - a bilinear interpolation (used by default)
INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.
INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood
INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood

the resized image will be back retrieved into RGBA buffer. So I think that additional operation of converting RGBA -> BGRA and after resizing back BGRA -> RGBA will be redundant and only will slow my image resizing. Maybe I am wrong and it matters the image will be in right format BGRA when using above interpolations.

IplImage *image = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 4);
    cvSetData(image, rgbaData, image->widthStep);

    // resize image
    float scale = 0.5;
    IplImage *resizedImage = cvCreateImage(cvSize(image->width*scale, image->height*scale), image->depth, image->nChannels);
    cvResize(image, resizedImage, CV_INTER_LANCZOS4);

To sum up my question is: Does it matter the image be in BGRA data format in IplImage * while I want to resize it using cvResize() and above interpolations?

Dan Mašek
  • 16,291
  • 6
  • 54
  • 80
Michał Ziobro
  • 9,353
  • 9
  • 67
  • 122

1 Answers1

2

No, there will be absolutely no difference. For proof, you can check here: opencv code. The code is a little hard to read, as it uses notations of mathematical interpolation formulas and sse intrinsics.

The same weights are used for interpolating R,G,B,A.

saurabheights
  • 3,520
  • 1
  • 28
  • 47
  • Though if you pass in data in the format requested you are robust to enhancements that, say, give less weight to the blue channel, or detect alpha all 255 in an early pass to reduce calculations. – Malcolm McLean Oct 07 '16 at 17:22
  • @MalcolmMcLean: I completely agree with you. That's what I was thinking and had to grep for resize code in opencv repo. It's probably a curiousity question or he may had image in BGRA mode and needed to do another processing in BGRA mode after resizing. In that case, any conversion would add more processing overhead. – saurabheights Oct 07 '16 at 17:32
  • Derived from your point, one should avoid passing Alpha channel if not needed. @MalcolmMcLean: Can you confirm if alpha channel early pass is done? I dont think I found anything like that. Also, this is more of user improper use of Opencv. – saurabheights Oct 07 '16 at 17:34
  • I tested it on images and it seems to work by passing in RGBA, RGB, GrayscaleAlpha, into IplImage, cvResize and getting them with cvGetRawData(), but I encounter problem with Grayscale 1 byte, 8bit depth, image has artefacts – Michał Ziobro Oct 07 '16 at 18:50
  • @MichałZiobro: Please can you post this as a different question. Please attach the input image and the code which failed to see what might be the issue. – saurabheights Oct 07 '16 at 19:15
  • http://stackoverflow.com/questions/39924462/opencv-using-cvimagecreate-with-grayscale-image-fails-and-resizing-usually-fa – Michał Ziobro Oct 07 '16 at 19:26