从两个图像中删除匹配像素以进行裁剪
我有两张非常相似的图像。
例如,假设我画了一个 200x200 的正方形,然后填充了多种颜色(例如,彩虹色填充),然后保存了图像。
然后我在正方形中间画了一颗星星,并用一些与正方形不同的颜色填充它,并将其保存为不同的文件。
几天后,我回来了,我真的很想要那颗星星,因为制作起来花了一些功夫,而且不想重做。我希望能够快速裁剪出该星星并将其隔离到自己的图像中(因为我使用的是没有图层的油漆)
但我知道带有星星的图像只是不带星星的图像的微小变化,所以理想情况下,如果我可以比较两个图像并删除星星周围的像素,那么我就可以找回我的星星。
已经有什么可以做到这一点了吗? 或者我不知道的现有工具提供的某些技术?
I have two images that are very similar.
So for example suppose I drew a 200x200 square, went and filled it a wide variety of colors (say, rainbow colored fill), and saved the image.
Then I drew a star in the middle of the square and also filled it with some variety of colors that is different from the square, and saved it as a different file.
Then some days later I come back and I really want that star because it took some effort to make and didn't want to redo it. I want to be able to crop out that star quickly and isolate it into its own image (because I was using paint which didn't have layers)
But I know that image with the star is just a minor variation of the image without the star, so ideally if I could just compare the two images and remove the pixels around the star, then I can get my star back.
Is there anything that does this already?
Or some technique that is provided by existing tools that I am unaware of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您有原始图像,您可以将两个图像读入您的程序并查看每个像素以查看它们是否具有相同的值,如果它们则将它们设置为黑色,如果不是,则保持它们不变;你的结果图像应该只有改变的像素,其余的都是黑色的。
这可能会给您带来“星星”本身的问题,因为星星中可能有一些点与原始图像上的点相同(即像素可能在两个图像上的两个地方都是绿色的)。在这种情况下,您可以查看周围的像素来提供帮助。
即:
此代码不考虑星形图像中与非星形图像的相同位置中的相同值相对应的像素的问题。有多种技术可以解决这个问题,但请记住,如果您查看相邻像素,则可能会在恒星的边界处遇到问题。
Assuming you have the original image, you can read both images into your program and look at each pixel to see if they are the same value, if they are then set them to black, if not, keep them as they are; your resultant image should have only the pixels that changed in it, with the rest being black.
This may give you an issue within the "star" itself, as there are likely to be points in the star that are the same as the points on the original image(i.e. a pixel may be green in both places on both images). In this case you can look at the surrounding pixels to help.
i.e.:
This code doesn't look at the issues with pixels in the star image that correspond to the same values in the same locations of the non-star image. There are several techniques to solve that, but bear in mind that if you are looking at neighboring pixels you may have issues at the boundaries of the star.