首页 文章

如何删除“绿屏”肖像背景

提问于
浏览
9

我正在寻找一种从很多图片中自动删除(=透明)“绿色屏幕”肖像背景的方法 .

我自己的尝试到目前为止......呃...不太成功 .

我正在四处寻找有关该主题的任何提示,解决方案或论文 . 商业解决方案也很好 .

在您发表评论之前,并说它不可能自动执行此操作:不,它不会使用它们 . 问题是他们用自己的生命来保护他们的算法,因此在菲律宾手工处理这个问题时,他们已经隐藏了一个工资过低的工作人员,因为我们每天都在谈几千张照片......但是,这种做法限制了它的用处有几个原因 . 所以我真的很喜欢这样的解决方案,可以在互联网离线时立即完成 .

EDIT :我的"portraits"描绘了有头发的人 - 这是一个非常棘手的部分,因为绿色背景会流入头发 . 另一个棘手的部分是,如果有可能在背景中的绿色和人们衣服中的相同绿色之间进行distingush . 我上面谈到的公司声称他们可以通过弄清楚绿色区域是否在焦点(锐利与模糊)来做到这一点 .

5 回答

  • 1

    PaintShop Pro允许您根据拾取颜色删除背景 . 他们还有一个删除背景棒,可以删除你触摸的任何东西(将这些像素转换为透明) . 您可以调整魔杖的“容差”,使其取出与您正在触摸的像素类似的像素 . 这在过去对我来说非常好 .

    To automate it, you'd program a script in PSP 做你想做的事,然后从你的程序中调用它 . 这可能是一种自动替换的方法,但它是最便宜,最快的解决方案,无需编写一堆C#/ C成像代码或支付商业代理费 .

    他们说,你付出的代价 .

  • 2

    由于您没有提供任何图像,我从网络中选择了一个具有色度键 with different shades of green and a significant amount of noise due to JPEG compression 的图像 .

    没有技术规范所以我使用了Java和Marvin Framework .

    input image:

    enter image description here

    步骤 1 只是将绿色像素转换为透明度 . 基本上它在HSV颜色空间中使用过滤规则 .

    enter image description here

    正如您所提到的,头发和一些边界像素呈现出与绿色混合的颜色 . 为了减少此问题,在步骤 2 中,对这些像素进行滤波和 balancer 以降低其绿色比例 .

    before:

    enter image description here

    after:

    enter image description here

    最后,在步骤 3 中,将梯度透明度应用于所有边界像素 . 高质量图像的效果会更好 .

    final output:

    enter image description here

    Source code:

    import static marvin.MarvinPluginCollection.*;
    
    public class ChromaToTransparency {
    
        public ChromaToTransparency(){
            MarvinImage image = MarvinImageIO.loadImage("./res/person_chroma.jpg");
            MarvinImage imageOut = new MarvinImage(image.getWidth(), image.getHeight());
            // 1. Convert green to transparency
            greenToTransparency(image, imageOut);
            MarvinImageIO.saveImage(imageOut, "./res/person_chroma_out1.png");
            // 2. Reduce remaining green pixels
            reduceGreen(imageOut);
            MarvinImageIO.saveImage(imageOut, "./res/person_chroma_out2.png");
            // 3. Apply alpha to the boundary
            alphaBoundary(imageOut, 6);
            MarvinImageIO.saveImage(imageOut, "./res/person_chroma_out3.png");
    
        }
    
        private void greenToTransparency(MarvinImage imageIn, MarvinImage imageOut){
            for(int y=0; y<imageIn.getHeight(); y++){
                for(int x=0; x<imageIn.getWidth(); x++){
    
                    int color = imageIn.getIntColor(x, y);
                    int r = imageIn.getIntComponent0(x, y);
                    int g = imageIn.getIntComponent1(x, y);
                    int b = imageIn.getIntComponent2(x, y);
    
                    double[] hsv = MarvinColorModelConverter.rgbToHsv(new int[]{color});
    
                    if(hsv[0] >= 60 && hsv[0] <= 130 && hsv[1] >= 0.4 && hsv[2] >= 0.3){
                        imageOut.setIntColor(x, y, 0, 127, 127, 127);
                    }
                    else{
                        imageOut.setIntColor(x, y, color);
                    }
    
                }
            }
        }
    
        private void reduceGreen(MarvinImage image){
            for(int y=0; y<image.getHeight(); y++){
                for(int x=0; x<image.getWidth(); x++){
                    int r = image.getIntComponent0(x, y);
                    int g = image.getIntComponent1(x, y);
                    int b = image.getIntComponent2(x, y);
                    int color = image.getIntColor(x, y);
                    double[] hsv = MarvinColorModelConverter.rgbToHsv(new int[]{color});
    
                    if(hsv[0] >= 60 && hsv[0] <= 130 && hsv[1] >= 0.15 && hsv[2] > 0.15){
                        if((r*b) !=0 && (g*g) / (r*b) >= 1.5){
                            image.setIntColor(x, y, 255, (int)(r*1.4), (int)g, (int)(b*1.4));
                        } else{
                            image.setIntColor(x, y, 255, (int)(r*1.2), g, (int)(b*1.2));
                        }
                    }
                }
            }
        }
    
        public static void main(String[] args) {
            new ChromaToTransparency();
        }
    }
    
  • 2

    如果您知道"green color",您可以在opencv C / C / Python中编写一个小程序来提取该颜色并替换为透明像素 .

  • 3

    看看这个帖子:http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=2&t=14394&start=0

    以及其中的链接到教程:http://tech.natemurray.com/2007/12/convert-white-to-transparent.html

    然后,只需编写一些脚本来查看完整的图像目录 . 很简单 .

  • 18

    123视频魔术绿色屏幕背景软件和还有一些刚刚删除绿屏背景希望这有助于

相关问题