如何使用基于均方误差的基于像素的图像比较度量来比较java中的图像集? [英] how to compare set of images in java using pixel based image comparision metric based on mean squared error?

查看:130
本文介绍了如何使用基于均方误差的基于像素的图像比较度量来比较java中的图像集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有一组图像。我需要比较它们。将来自一个图像的每个像素与数据集中所有其他图像中的相同位置处的像素进行比较。在对图像空间中的所有像素应用均方误差计算之后,识别一组不同的像素,其表示图像中具有变化的颜色值的像素。
我已经比较并存储了两个图像的文件中的相似像素。但是对于12个图像不能这样做。'code'

In my project i have a set of images. I need to compare them. Each pixel from one image is compared to the pixel at the same location in all other images in the dataset. After applying mean squared error calculation to all of the pixels in image space, a set of different pixels are identified which represents pixels with varying color values in the images. I have compared and stored similarities pixels in a file for two images.but can't do this for 12 images.'code'

import java.io.*;
import java.awt.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
class spe
{
    public static void main(String args[]) 
    throws IOException
    {
        long start = System.currentTimeMillis();
        int q=0;
            File file1 = new File("filename.txt");

        /* if file doesnt exists, then create it
        if (!file.exists()) {
                    file.createNewFile();
                }*/
        FileWriter fw = new FileWriter(file1.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);

                File file= new File("2000.png");
            BufferedImage image = ImageIO.read(file);
        int width = image.getWidth(null);
            int height = image.getHeight(null);
        int[][] clr=  new int[width][height]; 
        File files= new File("2002.png");
            BufferedImage images = ImageIO.read(files);
        int widthe = images.getWidth(null);
            int heighte = images.getHeight(null);
        int[][] clre=  new int[widthe][heighte]; 
        int smw=0;
        int smh=0;
        int p=0;
            //CALUCLATING THE SMALLEST VALUE AMONG WIDTH AND HEIGHT
            if(width>widthe)
            { 
                smw =widthe;
            }
            else 
            {
                smw=width;
            }
            if(height>heighte)
            {
                smh=heighte;
            }
            else 
            {
                smh=height;
            }
            //CHECKING NUMBER OF PIXELS SIMILARITY
            for(int a=0;a<smw;a++)
            {
                for(int b=0;b<smh;b++)
                {
                    clre[a][b]=images.getRGB(a,b);
                    clr[a][b]=image.getRGB(a,b);
                    if(clr[a][b]==clre[a][b]) 
                    {
                        p=p+1;
                        bw.write("\t");
                         bw.write(Integer.toString(a));
                        bw.write("\t");
                         bw.write(Integer.toString(b)); 
                        bw.write("\n");
                    }
                    else
                        q=q+1;
                }
            }

    float w,h=0;
    if(width>widthe) 
    {
        w=width;
    }
    else 
    {
        w=widthe;
    }
    if(height>heighte)
    { 
        h = height;
    }
    else
    {
        h = heighte;
    }
    float s = (smw*smh);
    //CALUCLATING PERCENTAGE
    float x =(100*p)/s;

    System.out.println("THE PERCENTAGE SIMILARITY IS APPROXIMATELY ="+x+"%");
    long stop = System.currentTimeMillis();
    System.out.println("TIME TAKEN IS ="+(stop-start));
    System.out.println("NO OF PIXEL GETS VARIED:="+q);
    System.out.println("NO OF PIXEL GETS MATCHED:="+p);
  }
}


推荐答案

你可以使用 Catalano Framework 来完成。有几种比较图像的指标,包括均方误差。

You can do it using Catalano Framework. There's several metrics to compare image, including mean square error.

示例:

FastBitmap original = new FastBitmap(bufferedImage1);
FastBitmap reconstructed = new FastBitmap(bufferedImage2);

ObjectiveFidelity o = new ObjectiveFidelity(original, reconstructed);

// Error total
int error = o.getTotalError();

//Mean Square Error
double mse = o.getMSE();

//Signal Noise Ratio
double snr = o.getSNR();

//Peak Signal Noise Ratio
double psnr = o.getPSNR();

所有这些指标都基于以下书籍:计算机成像:数字图像分析和处理 - Scott E Umbaugh 。

All these metrics are based in the book: Computer Imaging: Digital Image Analysis and Processing - Scott E Umbaugh.

下一版本(1.3)将包含 Derivative SNR

Next version (1.3) will contains Derivative SNR.

这篇关于如何使用基于均方误差的基于像素的图像比较度量来比较java中的图像集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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