當前位置: 首頁>>代碼示例>>Java>>正文


Java Raster.getSample方法代碼示例

本文整理匯總了Java中java.awt.image.Raster.getSample方法的典型用法代碼示例。如果您正苦於以下問題:Java Raster.getSample方法的具體用法?Java Raster.getSample怎麽用?Java Raster.getSample使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.image.Raster的用法示例。


在下文中一共展示了Raster.getSample方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: gethISTNode

import java.awt.image.Raster; //導入方法依賴的package包/類
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:ShortHistogramTest.java

示例2: MSE

import java.awt.image.Raster; //導入方法依賴的package包/類
/**
 * MSE algorithm.
 * @param im1 Input image1.
 * @param im2 Input image2.
 * @return Returns the similarity between two images.
 */
public static String MSE (BufferedImage im1, BufferedImage im2) {
    assert(
            im1.getType() == im2.getType()
                    && im1.getHeight() == im2.getHeight()
                    && im1.getWidth() == im2.getWidth());

    double mse = 0;
    int sum = 0;
    int width = im1.getWidth();
    int height = im1.getHeight();
    Raster r1 = im1.getRaster();
    Raster r2 = im2.getRaster();
    for (int i = 0; i < width; i++){
        for (int j = 0; j < height; j++){
            mse += Math.pow(r1.getSample(i, j, 0) - r2.getSample(i, j, 0), 2);
            if(r1.getSample(i, j, 0) == r2.getSample(i, j, 0)){
                sum++;
            }
        }
    }

    mse /= (double) (width * height);
    System.err.println("MSE = " + mse);
    float x = (100*sum)/(width * height);
    System.out.println("The percentage of similarity is approximately="+x+"%");
    return String.format("%.2f",mse);
}
 
開發者ID:Theldus,項目名稱:PSE,代碼行數:34,代碼來源:MSE.java

示例3: imageToMat

import java.awt.image.Raster; //導入方法依賴的package包/類
private static double[][] imageToMat(BufferedImage img) {
    int width = img.getWidth();
    int height = img.getHeight();
    double[][] imgArr = new double[width][height];
    Raster raster = img.getData();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            imgArr[i][j] = raster.getSample(i, j, 0);
        }
    }
    return imgArr;
}
 
開發者ID:emara-geek,項目名稱:arabic-characters-recognition,代碼行數:13,代碼來源:TestModel.java


注:本文中的java.awt.image.Raster.getSample方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。