【问题标题】:Entropy of image using its pdf使用其pdf的图像熵
【发布时间】:2013-12-31 12:27:30
【问题描述】:

对于给定的图像 Img,我计算了它的熵,得到的结果与 MATLAB 的熵函数相同。

hist_img = hist(Img(:),256);
pdf_img = hist_img./sum(hist_img);

H_pdf = sum(pdf_img.*log2(1./pdf_img))
H_test = entropy(input_img)

但是,当我尝试对差异图像执行相同操作时,我没有得到相同的结果

dif = input_img(2:end,:) - input_img(1:end-1,:);
hist_dif = hist(dif(:),256);
pdf_dif = hist_dif./sum(hist_dif);

H_pdf = pdf_dif.*log2(1./pdf_dif);
H_pdf (isnan(H_pdf )) = 0;
H = sum(H_pdf )
H_test = entropy(dif)

有什么建议可以解决这个问题吗?

【问题讨论】:

  • 考虑数据类型。 diff 图像中还有 256 个强度值吗?你会期待吗?值得深思。

标签: matlab entropy


【解决方案1】:

这是我的java代码

         public static double getShannonEntropy_Image(BufferedImage actualImage){
         List<String> values= new ArrayList<String>();
           int n = 0;
           Map<Integer, Integer> occ = new HashMap<>();
           for(int i=0;i<actualImage.getHeight();i++){
             for(int j=0;j<actualImage.getWidth();j++){
               int pixel = actualImage.getRGB(j, i);
               int alpha = (pixel >> 24) & 0xff;
               int red = (pixel >> 16) & 0xff;
               int green = (pixel >> 8) & 0xff;
               int blue = (pixel) & 0xff;
//0.2989 * R + 0.5870 * G + 0.1140 * B greyscale conversion
//System.out.println("i="+i+" j="+j+" argb: " + alpha + ", " + red + ", " + green + ", " + blue);
                int d= (int)Math.round(0.2989 * red + 0.5870 * green + 0.1140 * blue);
               if(!values.contains(String.valueOf(d)))
                   values.add(String.valueOf(d));
               if (occ.containsKey(d)) {
                   occ.put(d, occ.get(d) + 1);
              } else {
                  occ.put(d, 1);
              }
              ++n;
       }
    }
    double e = 0.0;
    for (Map.Entry<Integer, Integer> entry : occ.entrySet()) {
         int cx = entry.getKey();
         double p = (double) entry.getValue() / n;
         e += p * log2(p);
    }
 return -e;
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    相关资源
    最近更新 更多