public void grayImage() throws IOException{
File file = new File(System.getProperty("user.dir")+"/test.jpg");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
for(int i= 0 ; i < width ; i++){
for(int j = 0 ; j < height; j++){
int rgb = image.getRGB(i, j);
grayImage.setRGB(i, j, rgb);
}
}
File newFile = new File(System.getProperty("user.dir")+"/method1.jpg");
ImageIO.write(grayImage, "jpg", newFile);
}
img = cv2.imread('test.jpg',cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imwrite('PythonMethod.jpg', gray)
img = cv2.imread('test.jpg',cv2.IMREAD_COLOR)
h, w = img.shape[:2]
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
for j in range(w):
for i in range(h):
print str(i) + " : " + str(j) + " " + str(gray[i][j])
print img[h-1][w-1][0:3]
private static int colorToRGB(int alpha, int red, int green, int blue) {
int newPixel = 0;
newPixel += alpha;
newPixel = newPixel << 8;
newPixel += red;
newPixel = newPixel << 8;
newPixel += green;
newPixel = newPixel << 8;
newPixel += blue;
return newPixel;
}
public static void main(String[] args) throws IOException {
BufferedImage bufferedImage
= ImageIO.read(new File(System.getProperty("user.dir" + "/test.jpg"));
BufferedImage grayImage =
new BufferedImage(bufferedImage.getWidth(),
bufferedImage.getHeight(),
bufferedImage.getType());
for (int i = 0; i < bufferedImage.getWidth(); i++) {
for (int j = 0; j < bufferedImage.getHeight(); j++) {
final int color = bufferedImage.getRGB(i, j);
final int r = (color >> 16) & 0xff;
final int g = (color >> 8) & 0xff;
final int b = color & 0xff;
int gray = (int) (0.3 * r + 0.59 * g + 0.11 * b);;
System.out.println(i + " : " + j + " " + gray);
int newPixel = colorToRGB(255, gray, gray, gray);
grayImage.setRGB(i, j, newPixel);
}
}
File newFile = new File(System.getProperty("user.dir") + "/ok.jpg");
ImageIO.write(grayImage, "jpg", newFile);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有