PxConvolveImage (image, matrix)
[[v1 v2 v3] [v4 v5 v6] [v7 v8 v9]]
This function is used to convolve images. It applies the matrix to every point of the image, allowing for such effects as edge enhancement and image sharpening.
This example, ex_PxConvolveImage.g, is included in the product distribution.
#!/usr/cogent/bin/phgamma
/*
The following example demonstrates PxCopyImage(), PxGreyImage(),
and PxConvolveImage(). An image is loaded and converted to grey
scales. Then it is convolved for image sharpening, vertical and
horizontal edge enhancement, and laplace edge detection.
*/
PtInit(nil);
require_lisp("PhotonWidgets.lsp");
win = new(PtWindow);
// Load and display the image.
pic1 = PxLoadImage("taj.bmp");
lab1 = new(PtLabel);
lab1.label_type = Pt_IMAGE;
lab1.label_data = pic1;
// Copy the image and convert the colors to grey scales.
pic2 = PxCopyImage(pic1);
pic2 = PxGreyImage(pic2);
lab2 = new(PtLabel);
lab2.label_type = Pt_IMAGE;
lab2.label_data = pic2;
lab2.SetPos(300,0);
// Copy the grey_scaled image and convolve for image sharpening.
matrix = array(array(0,-1,0),
array(-1,5,-1),
array(0,-1,0));
pic3 = PxCopyImage(pic2);
pic3 = PxConvolveImage(pic3, matrix);
lab3 = new(PtLabel);
lab3.label_type = Pt_IMAGE;
lab3.label_data = pic3;
lab3.SetPos(600,0);
// Copy the grey_scaled image and convolve for vertical edge enhancement.
matrix = array(array(2,0,-2),
array(2,0,-2),
array(2,0,-2));
pic4 = PxCopyImage(pic2);
pic4 = PxConvolveImage(pic4, matrix);
lab4 = new(PtLabel);
lab4.label_type = Pt_IMAGE;
lab4.label_data = pic4;
lab4.SetPos(0,200);
// Copy the grey_scaled image and convolve for horizontal edge enhancement.
matrix = array(array(2,2,2),
array(0,0,0),
array(-2,-2,-2));
pic5 = PxCopyImage(pic2);
pic5 = PxConvolveImage(pic5, matrix);
lab5 = new(PtLabel);
lab5.label_type = Pt_IMAGE;
lab5.label_data = pic5;
lab5.SetPos(300,200);
// Copy the grey_scaled image and convolve for laplace edge detector.
matrix = array(array(1,1,1),
array(1,-8,1),
array(1,1,1));
pic6 = PxCopyImage(pic2);
pic6 = PxConvolveImage(pic6, matrix);
lab6 = new(PtLabel);
lab6.label_type = Pt_IMAGE;
lab6.label_data = pic6;
lab6.SetPos(600,200);
PtRealizeWidget(win);
PtMainLoop();
Copyright © 1995-2006 by Cogent Real-Time Systems, Inc. All rights reserved.