PImage filter(posterize) problem
in
Programming Questions
•
3 years ago
Hey guys,
In my program I need to reduce an image down to 4 colors, I'm using a combination of the GRAY and (POSTERIZE, 4) filters to achieve this. This works perfectly for an unmodified image, the problem I'm having is that if I resize the image it will result in more than 4 colors.
The following code works without an issue and works as expected.
pict.filter(GRAY);
pict.filter(POSTERIZE, 4);
image(pict, 0, 0);
If I try resizing before these commands, the resulting image is >10 colors even though I ran the posterize filter AFTER resizing...
pict.resize(128,128);
pict.filter(GRAY);
pict.filter(POSTERIZE, 4);
image(pict, 0, 0);
Does anyone know why this would be happening? I could understand if I did a color reduction before resize - but it's the last thing I do before setting the image. Also, if anyone else knows a different way I could take an image and reduce to a 2bit grayscale that would be great.
Thanks!
In my program I need to reduce an image down to 4 colors, I'm using a combination of the GRAY and (POSTERIZE, 4) filters to achieve this. This works perfectly for an unmodified image, the problem I'm having is that if I resize the image it will result in more than 4 colors.
The following code works without an issue and works as expected.
pict.filter(GRAY);
pict.filter(POSTERIZE, 4);
image(pict, 0, 0);
If I try resizing before these commands, the resulting image is >10 colors even though I ran the posterize filter AFTER resizing...
pict.resize(128,128);
pict.filter(GRAY);
pict.filter(POSTERIZE, 4);
image(pict, 0, 0);
Does anyone know why this would be happening? I could understand if I did a color reduction before resize - but it's the last thing I do before setting the image. Also, if anyone else knows a different way I could take an image and reduce to a 2bit grayscale that would be great.
Thanks!
1
