Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

from comments above: " Im going to take an average pixel count in the respective blocks"

ah, easy answer, then, - you want to iterate over blocks, not pixels, then, and take the average of the block:

Mat image = ... // for simplicity, let's assume a single channel , grayscale one
for (int y=0; y<image.cols-32; y+=32) {
    for (int x=0; x<image.rows-32; x+=32) {
        // get the average for the whole 32x32 block:
        Rect roi(x,y,32,32);
        Scalar mean,dev;
        meanStdDev(image(roi), mean, dev);
        // mean[0] is the mean of the first channel. do whatever you want with it
    }
}

have a look at the docs, too, please , and again, opencv is trying to be a "higher level" language.. try to learn the api, not to defeat it by working on a "per-pixel" basis

from comments above: " Im going to take an average pixel count in the respective blocks"

ah, easy answer, then, - you want to iterate over blocks, not pixels, then, and take the average of the block:

Mat image = ... // for simplicity, let's assume a single channel , grayscale one
for (int y=0; y<image.cols-32; y+=32) {
    for (int x=0; x<image.rows-32; x+=32) {
        // get the average for the whole 32x32 block:
        Rect roi(x,y,32,32);
        Scalar mean,dev;
        meanStdDev(image(roi), mean, dev);
        // mean[0] is the mean of the first channel. do whatever you want with it
    }
}

have a look at the docs, too, please , and again, opencv is trying to be a "higher level" language.. try to learn the api, not to defeat it by working on a "per-pixel" basis

from comments above: " Im going to take an average pixel count in the respective blocks"

ah, easy answer, then, - you want to iterate over blocks, not pixels, then, and take the average of the block:whole block at a time:

Mat image = ... // for simplicity, let's assume a single channel , grayscale one
for (int y=0; y<image.cols-32; y+=32) {
    for (int x=0; x<image.rows-32; x+=32) {
        // get the average for the whole 32x32 block:
        Rect roi(x,y,32,32);
        Scalar mean,dev;
        meanStdDev(image(roi), mean, dev);
        // mean[0] is the mean of the first channel. do whatever you want with it
    }
}

have a look at the docs, too, please