简体   繁体   English

从(嘈杂的)纯色背景中提取单个对象

[英]Extract single object from (noisy) solid background

I'm in the process of scanning old photographs, and I would like to automate the process of extracting the photograph from the (noisy) solid white background of the scanner so that I have a transparent photograph. 我正在扫描旧照片,我想自动化从扫描仪的(嘈杂的)纯白色背景中提取照片的过程,以便获得透明的照片。

I've tried to use OpenCV in Python, with techniques as edge/contour detection, but it would pick up the little specs of dust in the background and not generate a complete and correct transparency map. 我曾尝试在Python中使用OpenCV,并将其用作边缘/轮廓检测技术,但它会在后台拾取少量灰尘,而不会生成完整且正确的透明度贴图。

I have a sample: 我有一个样本:

样品扫描

and the desired result: 和预期的结果:

最终结果

there are the steps necessary to achieve your desired result (I implement them in C++ so I don't attach the code): 有一些步骤可以实现所需的结果(我用C ++实现了这些步骤,所以我不附加代码):

  1. Convert your image to grayscale. 将您的图像转换为灰度。
  2. Binarize it with a reasonably high threshold (I use 240). 使用合理的较高阈值将其二值化(我使用240)。
  3. Optionally apply opening operation. (可选)执行打开操作。
  4. Find contours. 查找轮廓。
  5. Get the biggest contour. 获得最大轮廓。
  6. Draw this biggest contour on another Mat filled with zeros 在另一个填充有零的垫子上绘制此最大轮廓
  7. You get the transparency mask 你会得到透明面膜

这是透明面膜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM