【问题标题】:Saving a labeled image保存带标签的图像
【发布时间】:2013-12-19 09:24:11
【问题描述】:

我已经使用函数bwlabel对图像进行了如下标记:

[L, num] = bwlabel(I, 8);

对于我正在使用的图像,假设我有 20 个标签。因此,当你运行unique(L) 时,你会得到一个最多 20 个的号码列表。

问题在于,当我 imwrite(L) 并在该新写入的图像上运行 unique 时,我将像素的值作为我标记的原始图像中的强度,而不是作为标记图像。

我如何imwrite 标记图像,同时将其保留为标记图像?

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    您可以将图像编写为索引图像(带有颜色图)

    imwrite( L, rand( 256, 3 ), 'myIndexedImage.png' ); % wrirte
    

    阅读

    [L cmp] = imread( 'myIndexedImage.png' ); % and you can ignore the colormap
    

    或者,转换为 uint8 并将标签保存为灰度(假设您的标签不超过 256 个)

    imwrite( uint8(L), 'myLabels.png' );
    

    阅读

    L = imread( 'myLabels.png' );
    

    注意不要使用任何压缩格式(例如 jpg)。

    【讨论】:

    • 感谢您的回答。你为什么使用rand( 256, 3 )?它代表什么?
    • @Simplicity 编写索引图像时,您需要提供颜色图和索引。你可以用任何n-by-3 矩阵替换rand(256,3),只要行数(n)大于等于L 中的标签数:n >= max(L(:))
    猜你喜欢
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    相关资源
    最近更新 更多