简体   繁体   English

如何将 rgb 转换为标签以进行图像分割

[英]How to convert rgb to labels for image segmentation

I have around 4000 rgb label images which are masks for some other images.我有大约 4000 个 rgb label 图像,它们是其他一些图像的掩码。 I can use this image label pair in the deep learning encoder-decoder structure (eg:UNet) architecture with the help of regression approach.我可以借助回归方法在深度学习编码器-解码器结构(例如:UNet)架构中使用此图像 label 对。 But I would like to do segmentation approach.但我想做分割方法。 For that how can I convert these images?为此,我该如何转换这些图像?

Sample image:示例图片: 在此处输入图像描述 (Above sample image should contain 3 classes. one oval shape part, the remaining red part, and the background white part. This can go upto 7 classes in some other image pairs) (上面的示例图像应该包含 3 个类。一个椭圆形部分,剩余的红色部分和背景白色部分。这可以 go 在其他一些图像对中最多 7 个类)

There is supposed to be 7 classes including background for the entire dataset.整个数据集应该有 7 个类,包括背景。 But when I tried to find the unique values in an RGB label, there are more than 30 unique value pairs coming.但是当我试图在 RGB label 中找到唯一值时,会有超过 30 个唯一值对出现。 Otherwise I would have select the unique rgb pair and do the processing.否则我将拥有 select 唯一的 rgb 对并进行处理。 How to overcome this如何克服这个

Here's one potential way to handle this (in MATLAB, but similar in other situations)这是处理此问题的一种潜在方法(在 MATLAB 中,但在其他情况下类似)

The image you have shared is rather pixelated, and hence quite difficult to handle.您共享的图像相当像素化,因此很难处理。 If your dataset contains similarly pixelated images, I'd explore some kind of pre-processing to get rid of spurious edge discolorations, as they mess up the clustering.如果您的数据集包含类似的像素化图像,我会探索某种预处理来消除虚假的边缘变色,因为它们会破坏聚类。 For the sake of demonstration here, I've created a test image with exactly three colors.为了在这里进行演示,我创建了一个正好包含三个 colors 的测试映像。

% Create a test image - one shared is very pixelated.
I = uint8(zeros(100, 100, 3));
I(10:20, 10:20, 1) = 255;
I(40:50, 40:50, 2) = 255;

If the number of colors here is unknown, but up to 7, here's a quick way to use imsegkmeans and it's 'C' output to find the number of unique centers.如果此处的 colors 的数量未知,但最多为 7 个,这是使用 imsegkmeans 的快速方法,它是 'C' output 来查找唯一中心的数量。

% Specify max clusters
maxNumClusters = 7;

% Run clustering using the max value
[~, C] = imsegkmeans(I, maxNumClusters);
nUniqueClusters = size(unique(C, 'rows'), 1);

'nUniqueClusters' should now contain the 'true' number of clusters in the image. “nUniqueClusters”现在应该包含图像中的“真实”数量的集群。 In a way, this is almost like finding the number of unique entries of pixel RGB triplets in the image itself - I think what's affecting your work is noise due to pixelation - which is a separate problem.在某种程度上,这几乎就像在图像本身中找到像素 RGB 三元组的唯一条目的数量——我认为影响你工作的是像素化引起的噪声——这是一个单独的问题。

[L, C] = imsegkmeans(I, nUniqueClusters);

% Display the labeled image for further verification.
B = labeloverlay(I, L);
figure, imshow(B)

One way to attempt to fix the pixelation problem is to plot a histogram of your image pixels (for one of the three color planes), and then managing the low values somehow - possibly marking all of them with a distinct new color that you know doesn't exist in your dataset otherwise (0, 0, 0), for example - and marking it's label to be 'unknown'.尝试解决像素化问题的一种方法是 plot 图像像素的直方图(对于三个颜色平面之一),然后以某种方式管理低值 - 可能用你知道的独特的新颜色标记所有这些不'否则在您的数据集中不存在 (0, 0, 0),例如 - 并将其 label 标记为“未知”。 This is slightly outside the scope of your original question - hence just a text description of it here.这稍微超出了您原始问题的 scope - 因此这里只是对它的文字描述。

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

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