我是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'))
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;
答案 0 :(得分:5)
除非使用标量double,否则无法添加整数和双精度数。例如,uint8(8) + 9
有效,而uint8(8) + [9 10]
则无效(给出的错误与您相同)。
将错误的行替换为
result(:,:,1) = double(image(:,:,1)) + smoothmask * diff_red; %this is line 82
也就是说,在添加之前将整数转换为双精度。
我假设image
是整数类型而其他变量是double。你的问题并不是很清楚。
image
作为变量名称并不是一个好主意,因为它会影响Matlab函数。