Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the same palette idea abid posted on SO, redone in c++ ;)

void posterize(Mat  & img, Mat &res, int bins)
{
    int q = 256/bins;
    Mat_<uchar> pal(1,256);
    for ( int c=0; c<256; c++ )
        pal(c) = saturate_cast<uchar>((((c/q) * q) * bins)/(bins-1));
    cerr << pal<< endl;
    LUT(img,pal,res);
}

int main( int argc, const char** argv )
{
    Mat img = imread("messi5.jpg");
    posterize(img,img,8);
    imshow("result",img);
    waitKey();
}

image description

the same palette idea abid posted on SO, redone in c++ ;)

void posterize(Mat  & img, posterize(const Mat &img, Mat &res, int bins)
{
    int q = 256/bins;
    Mat_<uchar> pal(1,256);
    for ( int c=0; c<256; c++ )
        pal(c) = saturate_cast<uchar>((((c/q) * q) * bins)/(bins-1));
    cerr << pal<< endl;
    LUT(img,pal,res);
}

int main( int argc, const char** argv )
{
    Mat img = imread("messi5.jpg");
    posterize(img,img,8);
    imshow("result",img);
    waitKey();
}

image description

the same palette idea abid posted on SO, redone in c++ ;)

void posterize(const Mat &img, Mat &res, int bins)
{
    int q = 256/bins;
    Mat_<uchar> pal(1,256);
pal(1,256); // make a lookup table for intensities
    for ( int c=0; c<256; c++ )
        pal(c) = saturate_cast<uchar>((((c/q) * q) * bins)/(bins-1));
    cerr << pal<< endl;
    LUT(img,pal,res);
LUT(img,pal,res);      // apply the lookup (swap pixel val & lookup val)
}

int main( int argc, const char** argv )
{
    Mat img = imread("messi5.jpg");
    posterize(img,img,8);
    imshow("result",img);
    waitKey();
}

image description