Ask Your Question

Revision history [back]

So basically your code will loop over the image using specified block, find out the local maxima and set all pixel to 0 other than the maxima.

First thing to take care that, you are modifying the source itself on each loop (making the surrounding zero) and you lost the original pixel data for next iteration.

So create a blank image same as source,

Mat dst(src.size(),CV_8UC1,Scalar(0));

Now inside loop find minmaxLoc, note that here you will get the max pixel value as well as the co-ordinates, you have to use that.

    subimage = image(range);
    subimageDest = dst(range); //Set ROI on destination image
    double max;
    Point maxLoc;
    minMaxLoc( subimage, NULL, &max, NULL, &maxLoc );

Now Set the maxima on dst image,<uchar>(maxLoc.y,maxLoc.x) =max;

Note: the code is not tested.!!