本文整理汇总了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;
}
示例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);
}
示例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;
}