Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 圆形梯度模糊滤波器_Java_Image Processing_Filter_Pixels - Fatal编程技术网

Java 圆形梯度模糊滤波器

Java 圆形梯度模糊滤波器,java,image-processing,filter,pixels,Java,Image Processing,Filter,Pixels,我正在做一个学校作业,我需要创建一个圆形渐变雾过滤器。我做了一些关于如何模糊图像的研究,我需要获取当前像素周围像素的颜色值,并对它们进行平均,为模糊图像设置新的颜色。到目前为止,我只关注模糊方面,我有以下代码: public void circularGradientBlur() { Pixel regularPixel = null; Pixel L_regularPixel = null; Pixel R_regularPixel = null;

我正在做一个学校作业,我需要创建一个圆形渐变雾过滤器。我做了一些关于如何模糊图像的研究,我需要获取当前像素周围像素的颜色值,并对它们进行平均,为模糊图像设置新的颜色。到目前为止,我只关注模糊方面,我有以下代码:

public void circularGradientBlur()
{
      Pixel regularPixel = null;
      Pixel L_regularPixel = null;
      Pixel R_regularPixel = null;
      Pixel T_regularPixel = null;
      Pixel B_regularPixel = null;
      Pixel blurredPixel = null;
      Pixel pixels[][] = this.getPixels2D();
      for (int row = 2; row < pixels.length; row++)
      {
         for (int col = 2; col < pixels[0].length - 1; col++)
         {
            regularPixel = pixels[row][col];
            if (row != 0 && col != 0 && row != 498 && col != 498)
            {
               L_regularPixel = pixels[row - 1][col];
               R_regularPixel = pixels[row + 1][col];
               T_regularPixel = pixels[row][col - 1];
               B_regularPixel = pixels[row][col + 1];
               blurredPixel.setRed((L_regularPixel.getRed() + R_regularPixel.getRed() + T_regularPixel.getRed() + B_regularPixel.getRed()) / 4);
               blurredPixel.setGreen((L_regularPixel.getGreen() + R_regularPixel.getGreen() + T_regularPixel.getGreen() + B_regularPixel.getGreen()) / 4);
               blurredPixel.setBlue((L_regularPixel.getBlue() + R_regularPixel.getBlue() + T_regularPixel.getBlue() + B_regularPixel.getBlue()) / 4);               
            }
         }
      }   
   }
public void circularGradientBlur()
{
Pixel regularPixel=null;
像素L_regularPixel=null;
像素R_regularPixel=null;
像素T_regularPixel=null;
像素B_regularPixel=null;
像素模糊像素=空;
像素像素[][]=this.getPixels2D();
用于(int row=2;row

当我尝试使用此代码时,在设置新颜色的行上会出现NullPointerException-blurredPixel.setRed()、blurredPixel.setGreen()、blurredPixel.setBlue()。这个错误让我很困惑,因为我有其他具有类似代码的方法,并且没有抛出这个错误。如果能得到任何帮助,我将不胜感激

您必须创建blurredPixel的实例。如果调用setter,它将始终为空。

请参见添加类似这样的代码
blurredPixel
添加一些示例并进行解释。
blurredPixel=new Pixel()然后执行设置程序。否则你会试图用不存在的东西做一些事情。动臂零点异常。