// Useful Filters // Copyright (C) 1995 Gatan Inc. // All Rights Reserved // Written by Chris Meyer // This file last updated 3/20/95 // // This function performs a 3x3 low pass filter on the // given real image and returns a new image that is // filtered. // Image ILLowPass( Image image ) { number width, height GetSize( image, width, height ) // This is inefficient in that it copies the // data, but it allows me to match the data // type easily. Image result = image SubArea imageS := image[ 1, 1, height - 2, width - 2 ] number nf = 1/9 result[ 1, 1, height - 2, width - 2 ] = nf * ( \ offset( imageS, -1, -1 ) + \ offset( imageS, -1, 0 ) + \ offset( imageS, -1, 1 ) + \ offset( imageS, 0, -1 ) + \ offset( imageS, 0, 0 ) + \ offset( imageS, 0, 1 ) + \ offset( imageS, 1, -1 ) + \ offset( imageS, 1, 0 ) + \ offset( imageS, 1, 1 ) ) return result } // // This function performs a 3x3 sharpen (high pass filter) // on the given real image and returns a new image that is // filtered. // Image ILHighPass( Image image ) { number width, height GetSize( image, width, height ) // This is inefficient in that it copies the // data, but it allows me to match the data // type easily. Image result = image SubArea imageS := image[ 1, 1, height - 2, width - 2 ] result[ 1, 1, height - 2, width - 2 ] = \ 9 * offset( imageS, 0, 0 ) - \ offset( imageS, -1, -1 ) - \ offset( imageS, -1, 0 ) - \ offset( imageS, -1, 1 ) - \ offset( imageS, 0, -1 ) - \ offset( imageS, 0, 1 ) - \ offset( imageS, 1, -1 ) - \ offset( imageS, 1, 0 ) - \ offset( imageS, 1, 1 ) return result } Image ILSharpen( Image image ) { return ILHighPass( image ) } // Examples of use: Image front := GetFrontImage() ShowImage( ILLowPass( front ) ) ShowImage( ILHighPass( front ) ) ShowImage( ILSharpen( front ) )