Matlab使用imread打开具有不同值的pgm图像 [英] Matlab is opening a pgm image with different values using imread

查看:283
本文介绍了Matlab使用imread打开具有不同值的pgm图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有1251个不同像素值的pgm图像,范围从0到1250.我知道这一点,因为我可以使用kate打开此图像文件并查看这些值.

I have a pgm image with 1251 different pixel values, ranging from 0 to 1250. I know this because I can open this image file with kate and see the values.

但是当我使用Matlab的imread打开相同的文件时,它还会返回1251个不同的像素值,但是这些值不是连续的.最小值为0,最大值为65483.

But when I open the same file using Matlab's imread, it also returns me 1251 different pixel values, but these values are not consecutive. The minimum value is 0 and the maximum value is 65483.

我想在for循环中遍历这些值,因此我需要读取文件中存在的原始值和连续值.如何在Matlab中做到这一点?

I want to iterate through these values in a for loop so I need to read the original and consecutive values as they exist in the file. How to do that in Matlab?

如果有人想尝试,那就是图片.

That's the image if someone wants to try.

图像

推荐答案

值将按比例缩放,以使您在查看图像时大部分不会变黑.

The values are scaled so that when you view the image it's not mostly black.

我通过检查以下内容来测试缩放是否可以使用整数整数截断:

I tested that the scaling works with straight integer truncation by checking that:

[A] = imread( 'myfile.pgm', 'pgm' );
p = sort(unique(A(:));
q = uint16((0:1250) * 65535 / 1251)';
all(p == q)                             % returns 1

因此,您可以像这样还原图像:

So, you can restore the image like this:

map = arrayfun( @(x) uint16(x * 1251 / 65536), 0:65535 );
B = arrayfun( @(x) map(x+1), A );

这篇关于Matlab使用imread打开具有不同值的pgm图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆