Ignore:
Timestamp:
Jan 3, 2005, 10:48:54 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • use OpenCV rather than Imlib2 if both are available.
  • cleaned up the slashdot code.
  • decode phpBB captchas.
  • added filter_contrast.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/src/filters.c

    r387 r389  
    143143}
    144144
    145 struct image *filter_equalize(struct image *img)
     145struct image *filter_equalize(struct image *img, int threshold)
    146146{
    147147    struct image *dst;
     
    155155        {
    156156            getpixel(img, x, y, &r, &g, &b);
    157             if(r < 200) r = 50; else r = 200;
     157            if(r < threshold) r = 0; else r = 255;
    158158            setpixel(dst, x, y, r, r, r);
    159159        }
     
    241241struct image *filter_median(struct image *img)
    242242{
    243 #define MSIZE 4
     243#define MSIZE 3
    244244    struct image *dst;
    245245    int x, y, i, j, val[MSIZE*MSIZE];
     
    279279}
    280280
     281struct image *filter_contrast(struct image *img)
     282{
     283    struct image *dst;
     284    int histo[256];
     285    int x, y, i, min = 255, max = 0;
     286    int r, g, b;
     287
     288    dst = image_new(img->width, img->height);
     289
     290    for(y = 0; y < img->height; y++)
     291        for(x = 0; x < img->width; x++)
     292        {
     293            getgray(img, x, y, &r);
     294            if(r < min) min = r;
     295            if(r > max) max = r;
     296        }
     297
     298    if(min == max)
     299        histo[min] = 127;
     300    else
     301        for(i = min; i < max; i++)
     302            histo[i] = (i - min) * 255 / (max - min);
     303
     304    for(y = 0; y < img->height; y++)
     305        for(x = 0; x < img->width; x++)
     306        {
     307            getgray(img, x, y, &r);
     308            setpixel(dst, x, y, histo[r], histo[r], histo[r]);
     309        }
     310
     311    return dst;
     312}
     313
Note: See TracChangeset for help on using the changeset viewer.