Redeye algorithm
- From: "Steve Horsley" <steve horsley gmail com>
- To: f-spot-list gnome org
- Subject: Redeye algorithm
- Date: Sat, 9 Sep 2006 14:11:47 +0100
I tried the redeye removal in F-spot (version 0.1.11 shipping with Ubuntu Dapper) and I was not very impressed. It seems to turn the colour grey without correcting the brightness. On the picture I tried it on, it left the subject with pupils almost exactly the same colour as her irises, as though she had cataracts.
I would like to suggest that you try the following algorithm instead.
I have tried this algorithm on Photoshop, pixel by pixel using mental arithmetic and it seems to work quite well.
I downloaded the 0.2.0
source and compile that so I could try the algorithm here, but it seems I'm not up to that yet - configure has a dependency on mono.pc that I can't find.
Please could you have a look at this and see if you think it's any use. It works by clamping the green to no more than twice the blue level and then clamping the red to no more than twice the green level. You could possible make it little more strict by using
1.5* instead of 2*. You need to leave some leeway for pinkish shades though, for when people accidentally select flesh rouns the eyes, and for coloured reflections in the pupils.
void f_pixbuf_remove_redeye (GdkPixbuf *src)
{
int width = gdk_pixbuf_get_width (src);
int height = gdk_pixbuf_get_height (src);
int i, j;
int r, g, b;
int channels = gdk_pixbuf_get_n_channels (src);
guchar *row = gdk_pixbuf_get_pixels (src);
for (i = 0; i < height; i++) {
guchar *col = row;
for (j = 0; j < width; j++) {
r = *col;
g = *(col + 1);
b = *(col + 2);
if(g > r * 2) {
g = r * 2;
*(col + 1) = g;
}
if(r > g * 2) {
r = g * 2;
*(col) = r;
}
col += channels;
}
row += gdk_pixbuf_get_rowstride (src);
}
}
Regards,
Steve Horsley.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]