ansi-c. High-Pass3 filter for .pgm pictures
I'm wandering through the web and none of tutorials I've read I don't really understand. How do I implementation of High-pass3 filter for .pgm pictures? I've struct of Image:
struct Image {
char* file_name; //name of .pgm file
char header[3];
int max_grey_value;
int height;
int width;
int **pixels; //pixels matrix
struct Image *next; //next element in the list
};
And now how to start? As far as I know I have to count some SUM, but I completely don't know how, and is thi开发者_开发知识库s sum one for whole image or it's for single pixel? Ok, then what? I need to divide it by some quotient. Is that argument of function or it should count it by itself. I'm really confused about this one. Can someone explain implementation of that filter to me in simple terms a beginner could understand?
First, you need to read your PGM image into your struct. If you don't know how to do this, read about the PGM format.
Once you've done that, you need to construct your filter. From your slightly ambiguous question, it sounds like you need a filter of size 3x3
. In theory, you can re-use your Image
struct to represent the filter -- the contents of the filter (the pixels
part) will depend on the specific filter that you're using (e.g. Laplacian or Sobel). After you've got your filter, convolve it with the image that you loaded in the first step. Technically, you're done here, but assuming you actually want to see the result, you'll need to write the convolution result to another PGM file.
You will need to write your own convolution function (this will involve the "count some SUM" part that you've mentioned in your question). You will also need your own image I/O functions, unless they've already been provided.
The convolution output will look something like this.
As a side note, it would be better to separate the representation of the image in memory and representation of image in a file system in your design. For example, currently, your Image
struct assumes that each image has a corresponding filename
, which will be meaningless if the Image
wasn`t loaded from the file system (e.g. if it's a filter that you created by yourself).
精彩评论