use*_*002 6 matlab image-processing normalization
我对图像标准化,图像范围和图像缩放非常困惑.我正在使用算法(我在上一个问题中上传了算法),在应用算法后,我使用维基百科中的这个公式来规范化图像:

使用getrangefromclass(filtImag1{i})MATLAB,在应用算法之前的矩阵范围是[0 255],并且在应用算法之后,范围是[0 1].
问题是我需要找一个参考来找出规范化公式是否正确?我还有5叠图像,每张图像包含600张图像.我已经为每个堆栈应用了算法,并且由于算法的结果是每个堆栈有10个图像,我最终会得到50个我需要分析的图像并将它们进行比较.我找到了50张图像的最大值和最小值,然后将每张图像传递到公式中以对图像进行标准化.
虽然图像的范围是[0 1]但图像的最大值是:max = 3.6714e + 004
为什么?不应该是1吗?这是正常化的正确方法吗?我该如何应用缩放?我需要这样做吗?
这是规范化代码:
%%%%%%%%%%%%%%Find Min and Max between the results%%%%%%%%%%%%%%%%%%%%%%%
pre_max = max(filtImag1{1}(:));
for i=1:10
new_max = max(filtImag1{i}(:));
if (pre_max<new_max)
pre_max=max(filtImag1{i}(:));
end
end
new_max = pre_max;
pre_min = min(filtImag1{1}(:));
for i=1:10
new_min = min(filtImag1{i}(:));
if (pre_min>new_min)
pre_min = min(filtImag1{i}(:));
end
end
new_min = pre_min;
%%%%%%%%%%%%%%normalization %%%%%%%%%%%%%%%%%%%%%%%
for i=1:10
temp_imag = filtImag1{i}(:,:);
x=isnan(temp_imag);
temp_imag(x)=0;
t_max = max(max(temp_imag));
t_min = min(min(temp_imag));
temp_imag = (double(temp_imag-t_min)).*((double(new_max)-double(new_min))/double(t_max-t_min))+(double(new_min));
imag_test2{i}(:,:) = temp_imag;
end
Run Code Online (Sandbox Code Playgroud)
编辑 我已根据建议的答案更改代码,但结果是黑色图像
%找到它们之间的最大值和最小值pre_max = max(sTStack {1}(:)); for i = 1:40 newMax = max(sTStack {i}(:)); if(pre_max
pre_min = min(sTStack {1}(:)); for i = 1:40 newMin = min(sTStack {i}(:)); if(pre_min> newMin)pre_min = min(sTStack {i}(:)); 结束t_min = pre_min;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%
for i = 1:40 NTstack {i} =(sTStack {i} - t_min)/(t_max-t_min); 结束
因为i = 10:10:40,imshow(NTstack {i}); colorbar colormap jet end
您提供的Wikipedia代码段是正确的,可以使用以下MATLAB代码对图像进行规范化:
%% Create an Example Image:
rand('seed', 1982);
n = 16;
myImg= rand(n,n)*.2 + .5;
%% Normalize the Image:
myRange = getrangefromclass(myImg(1));
newMax = myRange(2);
newMin = myRange(1);
myImgNorm = (myImg - min(myImg(:)))*(newMax - newMin)/(max(myImg(:)) - min(myImg(:))) + newMin;
Run Code Online (Sandbox Code Playgroud)
一些图像的问题在于它们虽然只占用一小部分可能的值.如果你的值可以在0和1之间,那么黑色将是0而白色将是1.但是,如果图像中最暗的点是.5而你的最亮点是.7那么它可能看起来已经被淘汰到你的处理或者用户何时可视化(请注意,由于这个原因,MATLAB的imagesc会在显示之前自动对图像进行规范化).
如果使用hist(myImg(:))查看图像的直方图,您可以了解图像实际使用的允许值的必须性.在标准化图像中,最小值将为0,最大值将为1(或您使用的任何范围).
实现此等式时常见的错误是没有正确放置括号,在缩放之前不减去图像的最小值,或者不在"newMin"中添加.
您可以在以下代码和图像中一起查看所有内容.请注意原始图像(1)如何仅使用空间(2)的一小部分,因此当我们不让imagesc自动缩放攀爬参数时,它看起来会褪色.然而,一旦我们归一化(3),图像具有非常暗和非常轻的值,并且直方图从0到1(4)一直延伸.虽然不清楚你的代码是做什么或不做什么,但将它与这个例子进行比较可以解决你的问题.
%% Create an Example Image:
rand('seed', 1982);
n = 16;
myImg= rand(n,n)*.2 + .5;
%% Normalize the Image:
myRange = getrangefromclass(myImg(1));
newMax = myRange(2);
newMin = myRange(1);
myImgNorm = (myImg - min(myImg(:)))*(newMax - newMin)/(max(myImg(:)) - min(myImg(:))) + newMin;
%% Display the Image:
figure(42);
clf;
% Display the original:
subplot(2,2,1);
imagesc(myImg);
set(gca, 'clim', [0,1]);;
title('(1) Original Image');
% Display the hist of the original:
subplot(2,2,3);
hist(myImg(:))
xlim([0,1]);
title('(2) Histogram Of Original Image');
% Display the normalized image:
subplot(2,2,2);
imagesc(myImgNorm);
title('(3) Normalized Image');
% Display the hist of the normalized image:
subplot(2,2,4);
hist(myImgNorm(:))
title('(4) Histogram of Normalized Image');
xlim([0,1]);
colormap gray
Run Code Online (Sandbox Code Playgroud)

编辑:
此外,关于getrangefromclass(...)将如何处理您的问题,还有一些重点要注意.此函数返回"基于其类的图像的默认显示范围"---也就是说,它返回MATLAB认为合理的值范围是该数据类型表示图片的值.对于uint8数据,这是[0,255].对于int16,这是[-32768,32767].对于你的情况,加倍,范围是[0,1],不是因为它是最小值和最大值,而是因为这是常规的,而双数据类型有一个特殊的表示,使得这个范围非常合理.请注意,范围与您的数据实际上是什么无关.如果您的数据小于或大于min和max将与MATLAB认为对图片有益的数据完全不同.在双倍或单倍的情况下,您的价值可能会更大.要将值标准化为[0,1]之间,我们可以使用我们一直在讨论的代码.
在这种情况下,我们创建一个具有大的正值和负值的随机图像,但我们将它们全部缩放到0到1之间.也就是说,我们制作最暗的颜色0和点亮的颜色1 ---而在最小的前面是负数千,最大的是正数千.但是,请注意直方图形状保持不变,而x轴值变为0,1.这应该说明为什么MATLAB范围是[0,1],但你的最小值/最大值是不同的----这很好,你的规范化代码将修复0到1之间的所有内容.
randn('seed', 1982);
myImg = randn(n,n)*1000;
% Normalize the Image:
myRange = getrangefromclass(myImg(1));
newMax = myRange(2);
newMin = myRange(1);
myImgNorm = (myImg - min(myImg(:)))*(newMax - newMin)/(max(myImg(:)) - min(myImg(:))) + newMin;
% Display the Image:
figure(42);
clf;
% Display the original:
subplot(2,2,1);
imagesc(myImg);
% set(gca, 'clim', [0,1]);;
title('(1) Original Image');
colorbar
% Display the hist of the original:
subplot(2,2,3);
hist(myImg(:))
title('(2) Histogram Of Original Image');
axis tight;
% Display the normalized image:
subplot(2,2,2);
imagesc(myImgNorm);
title('(3) Normalized Image');
colorbar
% Display the hist of the normalized image:
subplot(2,2,4);
hist(myImgNorm(:))
title('(4) Histogram of Normalized Image');
axis tight;
colormap gray
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
22533 次 |
| 最近记录: |