how can solve this error?

1 visualización (últimos 30 días)
faten emad
faten emad el 31 de En. de 2019
Respondida: James Long el 31 de En. de 2019
hi
i used this code
a=imread('6.jpg');
b= imread('text.png');
% b=im2bw(a);
[x y]=size(a);
a1=imresize(b,[x y]);
b1=zeros(x,y,'uint8');
for i=1:x
for j=1:y
b1(i,j)= a1(i,j)+a(i,j);
end
end
figure;imshow(a),title('first image')
figure;imshow(b),title('second image')
figure;imshow(b1),title('after add')
but it give me the error
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
how solve it?

Respuestas (1)

James Long
James Long el 31 de En. de 2019
can you attach a screenshot of the variable types?
it looks like you are trying to add a variable of type double to a variable of type unit8 or something along those lines. also, try to not designate the memory for b1 as type unit8 first. Rather, create b1 in the nested for-loop THEN change the variable type after the foor loop executes.
Also, this may help: https://www.mathworks.com/help/matlab/ref/typecast.html

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by