向图像文件添加噪点... [英] Adding noise to an image file...

查看:93
本文介绍了向图像文件添加噪点...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很明显,我遇到了问题.这是犯罪嫌疑人:

I am having problems, obviously. Here are the suspects:

class Pixel32
{
  unsigned char r, g, b, a;
  
  Pixel32(void);
  // This will set the values to zero, and a=255

};

class Image32
{
   int width, height;
   Pixel32* pixels;

   //...

   int Image32::AddRandomNoise(const float noise, Image32& img);
   // The goal is to add the random noise to each color of the
   // pixel and then rewrite them back to "img'
   // To access each pixel in image, there's a function in Image32
   // to return a reference.

   Pixel32& Image32::pixel(const int& x, const int& y);
   //...

   //Here's what I've tried.

   Pixel32& test = img.pixel(x,y);
   for (int y = 0; y < img.height(); y++)
   {
      for (int x = 0; x < img.width(); x++)
      {
          test.r += noise;
          test.g += noise;
          test.b += noise;
      }    
    }
};


我错误地认为通过创建对图像文件的引用
它将自动重写图像文件.
Image32类中有一个函数可以覆盖"="
操作员. (顺便说一句....这不是任务!!)

无论我发送多少噪音,生成的图像文件都是相同的
作为原始的.救命!

让我知道您是否需要更多信息.我从
输入所有这些内容 记忆,我目前时间紧迫...我在上班.

您能提供的任何帮助将不胜感激!!!!!

vdogamer.


I wrongly assumed that by creating a reference to the image file
that it would automatically rewrite the image file.
There is a function in the Image32 class that overwrites the "="
operator. (By the way....this is NOT for an assignment!!!)

No matter how much noise I send, the resulting image file is the same
as the original. Help!

Let me know if you needed more info. I''m typing all of this from
memory and I''m currently pressed for time...I''m at work.

Any help you can give will be greatly appreciated!!!

vdogamer.

推荐答案

Pixel32& test = img.pixel(x,y);
应该在内部循环之内,否则您将在相同的像素上写一遍
Pixel32& test = img.pixel(x,y);
should be inside the inner loop, otherwise you will write over and over the same pixel


这篇关于向图像文件添加噪点...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆