【发布时间】:2015-09-02 16:31:42
【问题描述】:
我已在 Java 中将原始图像读取为 BufferedImage,然后进行一些操作,我试图将图像阈值设置为高(255)或低(0),但是当我保存图像时,实际上我尝试覆盖它有了新值,像素值不仅是0和255,还会出现一些相邻的值,我不明白为什么。
阅读我的图片
File input = new File("/../Screenshots/1.jpg");
BufferedImage image = ImageIO.read(input);
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
Color c = new Color(image.getRGB(i, j));
powerspectrum[i][j] = (int) ((c.getRed() * 0.299)
+ (c.getGreen() * 0.587) + (c.getBlue() * 0.114));
}
}
限制我的图像
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
if (gradient[i][j] <= upperthreshold
&& gradient[i][j] >= lowerthreshold)
spaces[i][j] = 255;
else
spaces[i][j] = 0;
Color gradColor = new Color(spaces[i][j], spaces[i][j],
spaces[i][j]);
image.setRGB(i, j, gradColor.getRGB());
}
}
保存我的图像
File gradoutput = new File("/../Screenshots/3_GradThresh.jpg");
ImageIO.write(image, "jpg", gradoutput);
我不知道如何切断其他强度值。
【问题讨论】:
标签: java image image-processing threshold