gpt4 book ai didi

matlab - imread 如何缩放 12 位图像?

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:05 28 4
gpt4 key购买 nike

我有一个 12 位的 pgm-image,我用 imread 读取它。结果是一个 16 位图像,其值在 0 到 2^16 - 1 的整个范围内。

Matlab 如何扩展?将

 X = imread('filename');
X = uint16(double(X)*((2^12-1)/(2^16-1)));

恢复原来的强度?

最佳答案

MATLAB 确实可以正确加载 PGM 12 位图像。但是,在 MATLAB 加载图像后,图像值从 12 位重新缩放为 16 位。

MATLAB 使用以下算法将值从 12 位缩放到 16 位:

% W contains the the 12-bit data loaded from file. Data is stored in 16-bit unsigned integer
% First 4 bits are 0. Consider 12-bit pixel color value of ABC
% Then W = 0ABC
X = bitshift(W,4); % X = ABC0
Y = bitshift(W,-8); %Y = 000A
Z = bitor(X,Y); %Z = ABCA
% Z is the variable that is returned by IMREAD.

解决办法就是这样

function out_image = imreadPGM12(filename)
out_image = imread(filename);
out_image = floor(out_image./16);
return

或者向右移动 4 位:

function out_image = imreadPGM12(filename)
out_image = imread(filename);
out_image = bitshift(out_image,-4);
return

更多信息可以在这里找到: http://www.mathworks.com/matlabcentral/answers/93578-why-are-12-bit-pgm-images-scaled-up-to-16-bit-value-representation-in-image-processing-toolbox-7-10

关于matlab - imread 如何缩放 12 位图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27186874/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com