用Matlab进行硬阈值处理

时间:2015-05-12 21:11:00

标签: matlab image-processing

我有一个错误

Error using  .* 
Integers can only be combined with integers of the same class, or scalar doubles.

Error in wthresh (line 27)
    y   = x.*(abs(x)>t);

1 个答案:

答案 0 :(得分:0)

错误信息非常清楚。您将x乘以uint8和(abs(x)>t)这是合乎逻辑的。在乘以整数或转换为double时,您需要相同的类型。看看this question。将您的代码更改为以下内容:

I = im2double(imread('cameraman.tif')); %Converting pixel values from [0,255] to [0,1]
thr = 0.4;
hard= wthresh(I,'h',thr);
imshow(hard,[]);

或者

I = double(imread('cameraman.tif')); % Just change the data-type but keep values 
                                     % in the range [0,255].
thr = round(0.4*255); %Instead of converting pixel values, change the threshold.
hard= wthresh(I,'h',thr);