简体   繁体   English

如何将图像转换为组 colors?

[英]How can I transform an image to group colors?

Sorry if this has been asked before, but I couldn't find anything without having a more descriptive name of the transformation.抱歉,如果以前有人问过这个问题,但是如果没有更具描述性的转换名称,我找不到任何东西。

I would like to apply a transform on either a PIL image or an array of floats that represent a black and white image.我想对 PIL 图像或表示黑白图像的浮点数组应用变换。 Ideally the transform would alter the image like this (sorry, made in paint with a track pad):理想情况下,变换会像这样改变图像(对不起,用触控板涂漆):

所需的图像变换

I would consider it a bonus if it could preserve a black border around each color region, but that might be asking a lot depending on how the transform works.如果它可以在每个颜色区域周围保留一个黑色边框,我会认为它是一个奖励,但这可能会要求很多,具体取决于变换的工作方式。 Thanks in advance:)提前致谢:)

You can try morphological operation on the image:您可以尝试对图像进行形态学操作

import cv2 as cv
import numpy as np
img = cv.imread('img.png',0)

kernel = np.ones((5,5),np.uint8)
# Opening is erosion followed by dilation. It is useful in removing noise.
opening = cv.morphologyEx(img, cv.MORPH_OPEN, kernel)

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

相关问题 如何转换图像,使投影图像与原始图像相同 - How can I transform an image so that projected image is same as original 如何从第三个数组给出的对应关系将一个 numpy 标签数组转换为一个颜色数组? - How can I transform a numpy array of labels to an array of colors, from correspondance given by third array? 如何使用有两种颜色的 python PIL 创建图像? - How Can I create an image with python PIL where there are two colors? 如何使用 Python 有效地将像素数组 colors 转换为图像? - How can I convert an array of pixel colors into an image efficiently with Python? 如何将 png 图像转换为 RGBA colors 列表的列表? - How to transform a png image into a list of list of RGBA colors? 如何减少图像的 colors,使其具有确切数量的 colors? - How can I reduce colors of an image so it would have an exact number of colors? 我可以根据对象的变换值对对象进行分组吗? - Can I group objects based on their transform values? 如何将数组的二进制numpy列表转换为图像? - How can i transform my binary numpy list of arrays to an image? 如何对图像进行两次傅里叶逆变换? - How can I take inverse Fourier transform of an image twice? 我如何使用matplotlib.pyplot或python中的另一个库将Image1转换为Image2 - How can i transform Image1 to Image2 using matplotlib.pyplot or another library in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM