【发布时间】:2011-01-07 06:12:55
【问题描述】:
我正在做一个图像检测,我必须对每个红色、绿色和蓝色元素进行处理以获取边缘图(黑白形式的二进制图像)并将它们组合成一个以显示输出。在我提取每个红色、绿色和蓝色的元素并设置阈值以获得二进制图像后,它不会显示二进制图像。相反,它向我展示了灰度图像。有人可以帮助我吗?到目前为止,这是我的代码。
Buffered Image buff_red;
int[] process_red;
int width = 256;
int height = 256;
private void processActionPerformed(java.awt.event.ActionEvent evt) {
width = inputimage.getWidth(null);
height = inputimage.getHeight(null);
buff_red = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics r = buff_red.getGraphics();
r.drawImage(inputimage, 0, 0, null);
r.dispose();
//get the red element
process_red = new int[width * height];
counter = 0;
for(int i = 0; i < 256; i++) {
for(int j = 0; j < 256; j++) {
int clr = buff_red.getRGB(j, i);
int red = (clr & 0x00ff0000) >> 16;
red = (0xFF<<24)|(red<<16)|(red<<8)|red;
process_red[counter] = red;
counter++;
}
}
//set threshold value for red element
int threshold = 100;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int bin = (buff_red.getRGB(x, y) & 0x000000ff);
if (bin < threshold)
bin = 0;
else
bin = 255;
buff_red.setRGB(x,y, 0xff000000 | bin << 16 | bin << 8 | bin);
}
}
更新:
buff_red的初始化是在“get red element”(第一个循环)之前完成的,即:
buff_red = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics r = buff_red.getGraphics();
r.drawImage(inputimage, 0, 0, null);
我是否应该缓冲来自process_red 的图像并将其用于阈值方法以便我可以获得边缘图?
【问题讨论】:
-
你能告诉我你的代码吗?我也在做同样的过程,将 RGB 图像转换为灰度图像,然后将灰度图像转换为二进制图像。
-
您在这方面工作了多长时间?您可以向我们展示您所做的工作,我们可以帮助您解决问题。
标签: java image image-processing edge-detection