Path: utzoo!attcan!uunet!mcquaig!nmm From: nmm@mcquaig.UUCP (Neil M. McQuaig) Newsgroups: comp.graphics Subject: Re: Brighten Message-ID: <729@mcquaig.UUCP> Date: 2 Aug 90 03:43:41 GMT References: <1990Jul25.110057.1259@uoft02.utoledo.edu> <1990Jul31.233156.11888@herald.usask.ca> Reply-To: nmm@mcquaig.UUCP (Neil M. McQuaig) Organization: Micro Support Systems, Shreveport, LA Lines: 99 In article <1990Jul31.233156.11888@herald.usask.ca> you write: >From article <1990Jul25.110057.1259@uoft02.utoledo.edu>, by cscon113@uoft02.utoledo.edu: >> >> I am looking for a package to brighten an image. I have pbmplus, FBM >> and several conversion routines. I can't seem to find anything to >> use to brighten an image that won't leaveblack spots where the darkest >> parts of the image were. >> >> Any help appreciated, >> James H. Lewallen >James; > >Why not use ppmarith to add a constant value image to your image? This >avoids the problem of having zero-value pixels. As well, you could add >a low value (say 2 with a maxval of 255), and then multiply the image >by a constant value. This would give a better spread to the colour map, >yet still have no black spots in the final image. Another alternative: I needed a ppm program to write targa files. When I finished I found that many of the colors on the targa were too dim. The scaling bunched the rgb values into a small range at the low end of the spectrum. The solution I use is as follows and has worked ok so far. 1. Create a ppm histogram. 2. Scan the histogram to find the real max pixel value for red, green, or blue. 3. Use that value as the scaling factor to spread the colors through the output devices legal range (5 bits on a targa 16). This has the advantage that black stays black and does not turn to gray as it would if a constant were added to each pixel value. The code fragment below are from my ppmtotga routines. Hope this helps. If its dumb, I'm all ears. pixels = ppm_readppm( ifd, &cols, &rows, &maxval ); pm_close( ifd ); if (debug) fprintf(stderr,"maxval=%d MAXCOLORS=%d\n", maxval, MAXCOLORS); /* Figure out the colormap. */ if (tga_scale) { if (debug) fprintf( stderr, "Computing colormap..." ); chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &colors ); if ( chv == (colorhist_vector) 0 ) pm_error("too many colors - run through 'ppmquant 32768'", 0,0,0,0,0 ); if (debug) fprintf( stderr, " Done. %d colors found.)\n", colors ); /* get the max pixel value to use for scaling the colors */ for ( i = 0; i < colors; i++ ) { real_maxval = max(PPM_GETR( chv[i].color ), real_maxval); real_maxval = max(PPM_GETG( chv[i].color ), real_maxval); real_maxval = max(PPM_GETB( chv[i].color ), real_maxval); } ppm_freecolorhist(chv); if (debug) { fprintf( stderr, " Real maxval = %d\n", real_maxval); fflush (stderr); } } else { real_maxval = maxval; } ... put_pixel( ofd, pxl ) FILE *ofd; pixel pxl; { static pixval Red, Grn, Blu; static unsigned char ch[2]; /* Convert ppm map, scale to 5 bits to Targa and write it out */ Red = (int) PPM_GETR(pxl) * tga_maxval/real_maxval; Grn = (int) PPM_GETG(pxl) * tga_maxval/real_maxval; Blu = (int) PPM_GETB(pxl) * tga_maxval/real_maxval; ch[0] = (unsigned char) ((Blu & 0x1F) | ((Grn << 5) & 0xE0)); ch[1] = (unsigned char) (((Red << 2) & 0x7C) | ((Grn >> 3) & 0x03)); fputc(ch[0], ofd); fputc(ch[1], ofd); } -- Neil M. McQuaig 344 Millicent Way, Shreveport, LA 71106 VOICE: (318)868-5611 UUCP: mcquaig!nmm (318)865-1051 or uunet!mcquaig!nmm