保存带标签的图像 [英] Saving a labeled image
问题描述
我使用函数 bwlabel
按如下方式标记图像:
I have used the function bwlabel
to label an image as follows:
[L, num] = bwlabel(I, 8);
对于我正在使用的图片,我说有20个标签。因此,当您运行 unique(L)
时,您将获得最多20个数字列表。
For the the image I'm working with, say I have got 20 labels. Thus, when you run unique(L)
, you will get a number list up to 20.
问题就是当我 imwrite(L)
,并且在新写入的图像上运行 unique
时,我得到的值是像素作为我标记的原始图像中的强度,而不是标记图像。
The issue is that when I imwrite(L)
, and the run unique
on that new written image, I get the values of the pixels as their intensity in the original image I labeled, and not as a labeled image.
我怎样才能 imwrite
标记图像,同时将其保留为标记图像?
How can I imwrite
that labeled image, while keeping it as a labeled image?
推荐答案
您可以将图像写为索引图像(带有colormap)
You can write an image as an indexed image (with a colormap)
imwrite( L, rand( 256, 3 ), 'myIndexedImage.png' ); % wrirte
阅读
[L cmp] = imread( 'myIndexedImage.png' ); % and you can ignore the colormap
或者,转换为 uint8
并将标签保存为灰度(假设您的标签不超过256个)
Alternatively, convert to uint8
and save labels as gray scales (assuming you do not have more than 256 labels)
imwrite( uint8(L), 'myLabels.png' );
阅读
L = imread( 'myLabels.png' );
小心不要使用任何压缩格式(例如,jpg)。
Be careful NOT to use any compressive format (e.g., jpg).
这篇关于保存带标签的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!