【问题标题】:Matlab image normalization after filtering滤波后的Matlab图像归一化
【发布时间】:2012-06-04 11:34:43
【问题描述】:
我有以下代码,我试图在过滤后对我的图像进行标准化,但问题是,一旦它到达第 5 行,它就会将所有内容更改为 0,并返回给我黑色图像。有什么想法吗?
for i=1:10
temp_imag = imag_test1{i}(:,:);
t_max = max(max(temp_imag));
t_min = min(min(temp_imag));
temp_imag = (temp_imag-t_min).*double(((new_max-new_min)/(t_max-t_min)))+double(new_min);
imag_test1{i}(:,:) = temp_imag;
end
【问题讨论】:
标签:
image
matlab
image-processing
normalization
【解决方案1】:
你不知道 new_max 和 new_min 得到了哪些值,但无论如何,如果每在第 5 行 (temp_imag = (temp_imag-t_min).*double(((new_max-new_min)/(t_max-t_min)))+double(new_min);
) 之后一切都变为零,则有几种可能性:
imga_test{i} (1 <= i <= 10) 都为零,new_min 也为零。您是否检查过imga_test 的值,它们并非全为零并且它们有所不同?您可以为imga_test 创建示例数据,例如。通过使用rand 或randi。如果随机数据给您非零,则问题出在imga_test。
new_max-new_min 为零,这意味着new_max 和new_min 具有相同的值。您是否尝试过更改 new_max 和 new_min 的值并更改它们的差异?如果更改new_max、new_min 或两者的值都会给您非零值,则问题出在new_max 和new_min。
-
通过使用solve 来求解方程,例如。对于new_min:
solve('temp_imag = (temp_imag-t_min)*(((new_max-new_min)/(t_max-t_min)))+(new_min)', 'new_min'):
ans =
(new_max*t_min - new_max*temp_imag - t_min*temp_imag + t_max*temp_imag)/(t_max - temp_imag)
这第三种情况不太可能。
【解决方案2】:
我会尝试展示 pre vs.后处理图像:
figure();
for i=1:10
temp_imag = imag_test1{i}(:,:);
subplot( 1, 2, 1 ); imshow( temp_imag, [] ); title( 'pre' );
t_max = max(max(temp_imag));
t_min = min(min(temp_imag));
temp_imag = (temp_imag-t_min).*double(((new_max-new_min)/(t_max-t_min)))+double(new_min);
subplot( 1, 2, 2 ); imshow( temp_imag, [] ); title( 'post' );
imag_test1{i}(:,:) = temp_imag;
end