如何以编程方式删除黑色网格?

2024-09-29 18:39:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我的想法是:

  • 1.0. [unsolved, hard image-detection] Breaking image into squares and removing borders, surely other techniques!

  • 1.1. [unsolved] Imagemagick: crop (instructions here), remove certain borders -- this may take a lot of time to locate the grid, image detection problem (comparing white/black here) -- or there may be some magic wand style filter.

  • 1.2. [unsolved] Python: you probably need thisfrom PIL import Image.

显然,Gimp的橡皮擦是解决这个问题的错误方法,因为它速度慢而且容易出错。如何以编程方式删除网格?在

enter image description here

p.s.关于这个问题的非正式讨论图形.SEhere包含更多物理和机械黑客。


Tags: andimageheremaybreakingotherdetectionsquares
3条回答

如果所有图像都由灰色网格上的黑线组成,则可以调整白色阈值以移除网格(例如,使用ImageMagick):

convert -white-threshold 80% with-grid.png without-grid.png

你可能需要试验一下确切的阈值。80%的人用你的样品图片为我工作。这将使线条像素化。但也许再抽样可以将其降低到可接受的程度,例如:

^{pr2}$

对答案的反馈:emulbreh和fraxel

The python -version utilizes the ImageMagick so let's consider the ImageMagick. It does not work with colored version like the below due to different color-channel -profiles. Let's investigate this a bit further.

enter image description here

enter image description here

$ convert -white-threshold 0% bird.png without.png

enter image description here

This picture shows the amount of noise in the original scanned picture.

拼图:以移除右手角为例

I inversed the colors $ convert -negate whiteVersion.png blackVersion.png to make it easier to vizualise. Now with the below black photo, I wanted to remove the blue right corner i.e. make it black it means that I want to set BG channels to 0 of BG with 100% channel -value.

$ convert -channel BG -threshold 100% bbird.png without.png

enter image description here

enter image description here

Now the only thing left is of course Red -channel, I removed GB but white still have Red left. Now how can I remove just the right-hand -corner? I need to specify area and then do the earlier -operations.

How can I get this working with arbitrary photo where you want to remove certain color but leave some colors intact?

I don't know an easy way. The first problem is color-detection problem you specify some condition for colors (R,G,B) with some inequality. If the condition is true, you remove it in just the part. Now you do this for all basic colors i.e. when (R,G,B)=(100%,0,0), (R,G,B)=(0,100%,0) and (R,G,B)=(0,0,100%). Does there exist some ready implementation for this? Probably but it is much nicer to do it yourself, puzzle set!

必备知识

  • Tutorials here and here about Imagemagick.

  • In order to understand this topic, we need to know some basic physics: white color is a mixture of all colors and black consists of no colors.

所以我们可以设置一个比你的图像更亮的滤光片。使用PIL它可以如下所示:

import Image

def filter(x):
    #200 is our cutoff, try adjusting it to see the difference.
    if x > 200:
        return 255
    return x

im = Image.open('bird.png')
im = im.point(filter)
im.show()

使用此代码处理上载的图像可以得到:

{1美元^

在这种情况下,这是一个相当好的结果。如果您的图形比网格暗,您应该能够使用此方法而不会出现太多问题。在

相关问题 更多 >

    热门问题