-4

I have a red image - just for testing. The RGB Color is (217/18/36).

I perform the following code:

void QuaterImage(Mat& SrcImage, Mat& DestImage, bool Downsample) {
    int newWidth = 0, newHeight = 0;
    int newOrigWidth = 0, newOrigHeight = 0;

    if (SrcImage.cols % 2 > 0) { newOrigWidth = SrcImage.cols - 1; } else { newOrigWidth = SrcImage.cols; }
    if (SrcImage.rows % 2 > 0) { newOrigHeight = SrcImage.rows - 1; } else { newOrigHeight = SrcImage.rows; }

    if (SrcImage.depth() != CV_8U) { return; }

    newHeight = newOrigHeight / 2;
    newWidth = newOrigWidth / 2;

    DestImage = Mat(newWidth, newHeight, SrcImage.type());
    int r = 0, c = 0;
    uchar* DataPtr = SrcImage.ptr<uchar>(0);

    std::cout << std::to_string(*DataPtr) << std::endl;
    return;
}

It always returns "205".

If I change the image to be complettely yellow, it returns the exact same value. How can that be?

Regards, Jan

Jan021981
  • 521
  • 3
  • 28
  • 1
    you only consider the first byte of the bmp, is really what you want ? – bruno Apr 08 '19 at 16:23
  • 1
    please post a [mcve]. Here you're redefining `SrcImage` – Miki Apr 08 '19 at 16:27
  • Hi, postet the complette function. I know, I'm currently only accessing the first byte. And thats not, what I want - but currently, I'm searching for the error... If thats fixed, I'll continue. In the end, I like to design a function which can downsample an image bei half of the width and half of the hight as fast as possible. therefor I only want to take the average of four pixel for one pixel in the cores image. – Jan021981 Apr 08 '19 at 17:29
  • no, I only cut the part, where I calculate the new width and new hight. You can delete that part, because it's not used until now. The assigning of the pointer and the output is exactly the same. – Jan021981 Apr 08 '19 at 17:32
  • Maybe you just want this: https://stackoverflow.com/questions/10431919/downsampling-without-smoothing – drescherjm Apr 08 '19 at 17:33
  • something like that, but first I would like to know, where my mistake is... – Jan021981 Apr 08 '19 at 18:27

1 Answers1

0

Ok, sorry, I got it. You could not see it. I was giving the same image for SrcImage and DestImage, so the line DestImage = Mat(newWidth, newHeight, SrcImage.type());overwrote the image. Before that line, the values are correct.

Sorry for that...

Jan021981
  • 521
  • 3
  • 28