ansi-c。适用于 .pgm 图片的 High-Pass3 滤镜

发布于 2024-10-03 12:18:40 字数 439 浏览 2 评论 0原文

我在网上闲逛,我读过的教程都不是我真正理解的。如何为 .pgm 图片实现高通 3 滤波器?我已经有了图像结构:

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

};

现在如何开始?据我所知,我必须计算一些总和,但我完全不知道如何计算,这个总和是针对整个图像的还是针对单个像素的?好吧,然后呢?我需要将它除以某个商。是函数的参数还是应该单独计算它。我对这个问题真的很困惑。有人可以用初学者可以理解的简单术语向我解释该过滤器的实现吗?

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 this 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

探春 2024-10-10 12:18:40

首先,您需要将 PGM 图像读入结构中。如果您不知道如何执行此操作,请阅读PGM 格式

完成此操作后,您需要构建过滤器。从您稍微模棱两可的问题来看,听起来您需要一个大小为 3x3 的过滤器。理论上,您可以重复使用 Image 结构来表示过滤器 - 过滤器的内容(pixels 部分)将取决于您使用的特定过滤器正在使用(例如拉普拉斯或索贝尔)。获得过滤器后,将其与第一步中加载的图像卷积。从技术上讲,您已经完成了这里的操作,但假设您确实想查看结果,则需要 编写< /a> 将卷积结果写入另一个PGM文件。

您将需要编写自己的卷积函数(这将涉及您在问题中提到的“计算一些 SUM”部分)。您还需要自己的图像 I/O 函数,除非它们已经提供。

卷积输出将类似于这个

顺便说一句,最好在设计中将内存中图像的表示和文件系统中图像的表示分开。例如,目前,您的 Image 结构假定每个图像都有相应的 filename,如果 Image 不是从以下位置加载的,则该文件名将毫无意义:文件系统(例如,如果它是您自己创建的过滤器)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文