【问题标题】:The Normalization of Image gives black image图像的归一化给出黑色图像
【发布时间】:2014-03-04 09:59:23
【问题描述】:

我想增强潜在指纹图像,因为我已经做了 首先对图像进行标准化我已经编写了代码 指纹图像的归一化,但它完全输出 黑色图像我想知道下面的代码有什么问题是java 类。

package com.quality;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

class ImageArray
{
    double M;
    double VAR;
    BufferedImage img;
    int w;
    int h;
  double[][] imagedata; 
  double [][] outputdata;


public ImageArray()
        {
            try {
                img = ImageIO.read(new File("Sample7.jpg"));
                w = img.getWidth();
                h = img.getHeight();
                imagedata = new double[w][h];
                outputdata = new double[w][h];
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public void Mean()
        {

    for(int x=0;x<imagedata.length;x++)
    {
        for(int y=0;y<imagedata[x].length;y++)
        {
            Color color = new Color(img.getRGB(x, y));

            imagedata[x][y] = color.getRed();
        }
    }


    for(int x=0;x<imagedata.length;x++)
    {
        for(int y=0;y<imagedata[x].length;y++)
        {
            M+=(imagedata[x][y]);
        }
    }

    M =   M/(w*h);
    System.out.println("mean"+M);

    }



public void Variance()
        {

            for(int x=0;x<imagedata.length;x++)
            {
                for(int y=0;y<imagedata[x].length;y++)
                {
                    VAR+=Math.pow(imagedata[x][y]-M,2);
                }
            }

        VAR = VAR/(w*h);
            System.out.println("varience"+VAR);
        }



public void normalization(double mean,double varience)
        {
            int M0 = 100;
            int VAR0 = 100;

            for(int x=0;x<imagedata.length;x++)
            {
                for(int y=0;y<imagedata[x].length;y++)
                {
                    if(imagedata[x][y]>mean)
                    {
                        outputdata[x][y]=M0+(Math.sqrt(VAR0*Math.pow(imagedata[x][y]-M, 2)))/VAR;
                    }else
                    {
                        outputdata[x][y]=M0-(Math.sqrt(VAR0*Math.pow(imagedata[x][y]-M, 2)))/VAR;
                    }
                }
            }

        }




public void DrawImage() throws IOException
        {
            BufferedImage outputImage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);

            for(int x=0;x<outputdata.length;x++)
            {
                for(int y=0;y<outputdata[x].length;y++)
                {
                    outputImage.setRGB(x, y, (int) outputdata[x][y]);
                }
            }



            Graphics2D g2 = outputImage.createGraphics();
            g2.drawImage(outputImage, null, null);

            File imageFile = new File("output.jpg");
            ImageIO.write(outputImage, "jpg", imageFile);

        }







 public static void main(String args[])
            {

                try {
                    ImageArray abc = new ImageArray();
                    abc.Mean();
                    abc.Variance();
                            abc.normalization();
                    abc.DrawImage();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
}

【问题讨论】:

    标签: java image-processing normalization


    【解决方案1】:

    你可能想给表达式加上括号:

    M =   M/w*h;
    

    作为

    M =   M/(w*h);
    

    【讨论】:

    • 是的,VAR = VAR/w*h;
    • 我把它留给学生做练习。 ;-)
    猜你喜欢
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    相关资源
    最近更新 更多