【问题标题】:Selecting similar coloured pixels in ImageView similar to magic wand tool in Photoshop在 ImageView 中选择相似颜色的像素,类似于 Photoshop 中的魔术棒工具
【发布时间】:2014-01-03 10:07:16
【问题描述】:

我也尝试过使用 OpenCV-Sample-Color-blob-detection 代码,但我真正想要的是在位图上工作,而不是在相机视图上工作。

我试过下面的代码,

public boolean onTouch(View v, MotionEvent event)
    {
        int x = (int)event.getX();
        int y = (int)event.getY();

        Log.e("Test", "Touch image coordinates:"+x+" , "+y);
        Log.e("Test", "color:"+bimp.getPixel(x, y));

        int xclear = bimp.getPixel(x, y) ;

        int xclear_red = Color.red(xclear) ;
        int xclear_blue = Color.blue(xclear) ;
        int xclear_green = Color.green(xclear) ;

        if ((x < 0) || (y < 0) || (x > bimp.getWidth()) || (y > bimp.getHeight())) 
            return false;

        for(int x1=0 ; x1<bimp.getWidth() ; x1++)
        {
            for(int y1=0 ; y1<bimp.getHeight() ; y1++)
            {
                int px = bimp.getPixel(x1, y1);
                int px_red = Color.red(px) ;
                int px_blue = Color.blue(px) ;
                int px_green = Color.green(px) ;

                if((px_red+10 > xclear_red) && (px_red -10 < xclear_red))
                {
                    if((px_blue > xclear_blue) && (px_blue-10 < xclear_blue))
                    {
                        if((px_green+10 > xclear_green) && (px_green-10 < xclear_green))
                        {
                            bimp.setPixel(x1, y1, Color.TRANSPARENT);
                        }
                    }
                }
            }

            if(x1 == bimp.getWidth()-1 )
                img.setImageBitmap(bimp);
        }

        return false; // don't need subsequent touch events
    }

它正在制作类似于(+ 或 - 10)像素颜色的像素,我已经触及透明。

但我真正想要的是(如下图所示)。

即选择相似颜色的像素(显示为红色边框)作为photoshop中魔杖工具的动作。这样我就可以使所选部分透明或裁剪。

请给我一些建议。在此先感谢。

【问题讨论】:

    标签: android image bitmap selection


    【解决方案1】:

    我认为您需要的是洪水填充算法。可能对你有点用处。

    http://en.wikipedia.org/wiki/Flood_fill

    【讨论】:

    • 教程在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多