advertisement

Article:
  Bitmap Image Filters
Subject:   I made digital Laplacian image sharpener
Date:   2002-08-08 21:31:22
From:   psheldon
I sure hope this code doesn't pile up into one paragraph since there are no linefeed whitespaces.


We'll see.


Allocated another gray structure :
NSBitmapImageRep *destImageRepSharpened = same expression as destImageRep.


Then added :
unsigned char *destDataSharpened = [destImageRepSharpened bitmapData];
because I wasn't shown how to do the in place computation of the digital Laplacian.


Then I added to a line :
unsigned char *p1, *p2, *p2xp1, *p2xm1,*p2yp1,*p2ym1;
to capture pixels around on a cross of x1 and y1 from pixel at address p2.


After the grayifying loop, I put another loop :

//Implement digital Laplacian (see "Digital Picture Processing" p.185 by Rosenfeld and Kak copyright 1976)
for ( y = 0; y < h; y++ ) {
for ( x = 0; x < w; x++ ) {
// Get a pointer to the to be sharpened out pixel
p2Sharpened = destDataSharpened + y * w + x;


//Get terms of laplacian to fold or convolve into this pixel
p2 = destData + y * w + x;
p2xp1 = destData + y * w + (x+1);
p2xm1 = destData + y * w + (x-1);
p2yp1 = destData + (y+1) * w + x;
p2ym1 = destData + (y+1) * w + x;


//Average in color into an out gray
//(must cluge digital Laplacian with factor to insure that it is dark)
//this differencing of a pixel with the average of it and its surround
//is kind of like what goes on in the retina (reference too long ago to remember)
*p2Sharpened = (unsigned char)rint( - (*p2-(*p2+*p2xp1+*p2xm1+*p2yp1+*p2ym1) / 5) * 0.1 );
}
}


[destImage addRepresentation:destImageRepSharpened];
return destImage;


1 to 1 of 1
  1. can get indents back if set prefs in PB
    2002-08-08 21:37:16  psheldon [View]

1 to 1 of 1