【问题标题】:Hard Thresholding with Matlab使用 Matlab 进行硬阈值处理
【发布时间】:2015-05-12 21:11:00
【问题描述】:

我有一个错误

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);

【问题讨论】:

  • 我没有 wthresh(),但我希望您需要将 I 转换为 double,它将以 uint8 的形式出现。做I = double(I).
  • 当我使用 double 时,原始图像变化很大,太白了。
  • 是的,如果你想显示它,image() 期望它在双倍时以 0-1 进行缩放,如果是 uint8 则为 0-255。鉴于您的阈值,实际上您可能追求的是 I = double(I)/255,它将其重新调整为 0-1。

标签: matlab image-processing


【解决方案1】:

错误信息很清楚。您将x 相乘,这可能是一个 uint8 和(abs(x)>t),这是一个逻辑。将整数相乘或转换为双精度时需要相同的类型。也请看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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 1970-01-01
    相关资源
    最近更新 更多