help ! how do i fix this error : Error using .* Integers can only be combined with integers of the same class, or scalar doubles.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
clear;clc;
im=imread(' image.png');
R=im(:,:,1);
G=im(:,:,2);
B=im(:,:,3);
Y=0.299*R + 0.587*G + 0.114*B;
im = im2double(rgb2gray(im));
[~, T]=graythresh(im);
bwImage=imbinarize(im,T);
[M,~] = size(im);
[label,num] = bwlabel(im);
coor = zeros(num,2);
for n = 1:num
[x,y] = find(label==n);
m_iN = length(x);
for k = 1:m_iN
pSrc(k) = Y(x(k),y(k));
tmp_B(k,1) = x(k)^2;
tmp_B(k,2) = y(k)^2;
tmp_B(k,3) = x(k);
tmp_B(k,4) = y(k);
tmp_B(k,5) = 1;
end
[Q R]=qr(tmp_B);
pSrc=pSrc';
S = Q'*pSrc;
S = S(1:5);
R1 = R(1:5,1:5);
C = R1\S;
coor(n,:) = [-0.5*C(1)/C(3),-0.5*C(2)/C(4)];
end
0 comentarios
Respuestas (4)
KSSV
el 14 de Abr. de 2022
Read about class. To multiply two variables, they should be of same class.
a = int8(6) ;
b = int16(6) ;
c = int8(6) ;
class(a)
class(b)
class(c)
a*c % no error
a*int8(b) % no error, class int16 converted to class int8
a*b % error
Walter Roberson
el 14 de Abr. de 2022
The code you posted does not contain any .* operations, unless inside one of the calls.
But
S = Q'*pSrc;
If I scan correctly, Q is double precision but pSrc is uint8.
Y=0.299*R + 0.587*G + 0.114*B;
R G B are all uint8, and double times array of uint8 gives uint8, so Y will be uint8. Later you copy values out of Y into pSrc without having initialized pSrc so the uint8 type will be copied so pSrc will be uint8.
0 comentarios
Bruno Luong
el 14 de Abr. de 2022
Add cast to double statement after reading your image
im=imread(' image.png');
im = double(im);
...
yanqi liu
el 19 de Abr. de 2022
im=imread('football.jpg');
im=imresize(im,20/size(im,1),'bilinear');
R=im(:,:,1);
G=im(:,:,2);
B=im(:,:,3);
Y=0.299*R + 0.587*G + 0.114*B;
im = im2double(rgb2gray(im));
[~, T]=graythresh(im);
bwImage=imbinarize(im,T);
[M,~] = size(im);
[label,num] = bwlabel(im);
coor = zeros(num,2);
for n = 1:num
[x,y] = find(label==n);
m_iN = length(x);
for k = 1:m_iN
pSrc(k) = Y(x(k),y(k));
tmp_B(k,1) = x(k)^2;
tmp_B(k,2) = y(k)^2;
tmp_B(k,3) = x(k);
tmp_B(k,4) = y(k);
tmp_B(k,5) = 1;
end
[Q, R]=qr(tmp_B);
pSrc=pSrc';
S = double(Q')*double(pSrc);
S = S(1:5);
R1 = R(1:5,1:5);
C = R1\S;
coor(n,:) = [-0.5*C(1)/C(3),-0.5*C(2)/C(4)];
end
coor
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Programming 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!