+;matlab中的图像算子
我对matlab非常陌生,我正在尝试运行一个处理图像的程序。下面是我的代码中适用于该问题的部分+;matlab中的图像算子,matlab,Matlab,我对matlab非常陌生,我正在尝试运行一个处理图像的程序。下面是我的代码中适用于该问题的部分 function result = shadowremoval(image, type, mask) % computing size of the image s_im = size(image); % creating a shadow segmentation if no mask is available if (~exist('mask','var')) gra
function result = shadowremoval(image, type, mask)
% computing size of the image
s_im = size(image);
% creating a shadow segmentation if no mask is available
if (~exist('mask','var'))
gray = rgb2gray(image);
mask = 1-double(im2bw(gray, graythresh(gray)));
end
% structuring element for the shadow mask buring, and the shadow/light
% core detection
strel = [0 1 1 1 0; 1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1; 0 1 1 1 0];
% computing shadow/light core (pixels not on the blured adge of the
% shadow area)
shadow_core = imerode(mask, strel);
lit_core = imerode(1-mask, strel);
% smoothing the mask
smoothmask = conv2(double(mask), double(strel/21), 'same');
% averaging pixel intensities in the shadow/lit areas
shadowavg_red = sum(sum(image(:,:,1).*shadow_core)) / sum(sum(shadow_core));
litavg_red = sum(sum(image(:,:,1).*lit_core)) / sum(sum(lit_core));
% additive shadow removal
% compiting colour difference between the shadow/lit areas
diff_red = litavg_red - shadowavg_red;
% adding the difference to the shadow pixels
result(:,:,1) = image(:,:,1) + smoothmask * diff_red; %this is line 82
这就是我得到的错误:
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
Error in shadowremoval (line 82)
result(:,:,1) = image(:,:,1) + smoothmask * diff_red;
除非使用标量双精度,否则不能添加整数和双精度。例如,
uint8(8)+9
有效,而uint8(8)+[9 10]
无效(给出与您得到的错误相同)
替换导致错误的行
result(:,:,1) = double(image(:,:,1)) + smoothmask * diff_red; %this is line 82
也就是说,在进行加法之前,将整数强制转换为双倍
我假设image
是整数类型,其他变量是双精度的。从你的问题上看不太清楚
顺便说一句,使用
image
作为变量名不是一个好主意,因为它会隐藏Matlab函数。除非使用标量双精度,否则不能添加整数和双精度。例如,uint8(8)+9
有效,而uint8(8)+[9 10]
无效(给出与您得到的错误相同)
替换导致错误的行
result(:,:,1) = double(image(:,:,1)) + smoothmask * diff_red; %this is line 82
也就是说,在进行加法之前,将整数强制转换为双倍
我假设image
是整数类型,其他变量是双精度的。从你的问题上看不太清楚
顺便说一句,使用image
作为变量名不是一个好主意,因为它隐藏了一个Matlab函数