I would like to know where I can find 3 good algorithms, or 3 examples of C code to :
- apply a sketch effect on an image (black and white)
- apply a sketch effect on an image (color)
- apply a cartoon effect on an image (color)
I already have a code for the black and white sketch, but it's too white..
void sketchFilter(int *pixels, int width, int height) {
changeImageToGray(pixels, width, height);
int *tempPixels = new int[width * height];
memcpy(tempPixels, pixels, width * height * sizeof(int));
int threshold = 7;
float num = 8;
for (int i = 1; i < height - 1; i++) {
for (int j = 1; j < width - 1; j++) {
Color centerColor(tempPixels[i * width + j]);
int centerGray = centerColor.R();
Color rightBottomColor(tempPixels[(i + 1) * width + j + 1]);
int rightBottomGray = rightBottomColor.R();
if (abs(centerGray - rightBottomGray) >= threshold) {
pixels[i * width + j] = RGB2Color(0, 0, 0); // black
}
else {
pixels[i * width + j] = RGB2Color(255, 255, 255); // white
}
}
}
delete [] tempPixels;
}
Any way to improve this code, or should I go with a completely different? How can I do both color cartoon (doodle?) and color sketch? Thanks!