找到连接的像素 [英] finding connected pixel

查看:56
本文介绍了找到连接的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理图像处理项目,因为我已经给出了特定像素,我想找出连接到该pixel.ex的所有像素。我给了特定位置的白色像素我想找到所有连接的像素到白色(只连接到白色)怎么做或者如何检查像素是否连接。

i am working on image processing projects in that i have given specific pixel i want to find out all pixel which are connected to that pixel.ex. i have give white pixel for specific position i want to find all connected pixel to the white (only connected to white ) how can do that or how can check pixel are connected or not.

推荐答案

REPOST!



查找连接像素 [ ^ ]
REPOST!

finding connected pixel[^]


使用Flood Fill算法我已经完成了这个





by using Flood Fill algorithm i have done this


import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Point;
import java.io.File;
 
class mm1
{
	  private static void repaintAndDelay(BufferedImage image)
	  {
	    _imageLabel.setIcon(new ImageIcon(image));
	    _imageLabel.repaint();
	    try { Thread.sleep(1); } catch (Exception ignore) {}
	  }
	 
  public static void floodFill(BufferedImage image, int x,int y, int fillColor)
  {
    java.util.ArrayList<point> examList=new java.util.ArrayList<point>();
 
    int initialColor=image.getRGB(x,y);
    examList.add(new Point(x,y));
 
    while (examList.size()>0)
    {
      Point p = examList.remove(0);
      if (image.getRGB(p.x,p.y)==initialColor)
      {
        x = p.x;  y = p.y;
        image.setRGB(x, y, fillColor); 
 examList.add(new Point(x-1,y));        
        examList.add(new Point(x+1,y));        
        examList.add(new Point(x,y-1));        
        examList.add(new Point(x,y+1));        
        repaintAndDelay(image); 
      }
    }
 
  }
  public static int packRgb(int r,int g,int b)
  {
    return (r*256+g)*256+b;
  }
 static JLabel _imageLabel;
  public static void main(String[] args) throws Exception
  {
    BufferedImage image=ImageIO.read(new File("test1.png"));
    JLabel imageLabel=new JLabel();
    _imageLabel = imageLabel; 
    imageLabel.setIcon(new ImageIcon(image));
   javax.swing.JFrame window=new javax.swing.JFrame();
    window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
    window.add(imageLabel);
  window.pack();
    window.setVisible(true);
    int yellow = packRgb(255,0,0);
    int x=100, y=100;  
    floodFill(image,x,y, yellow);
 
    imageLabel.setIcon(new ImageIcon(image));
    
 
  }
}</point></point>


这篇关于找到连接的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆