本文整理匯總了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;
}