help ! how do i fix this error : Error using .* Integers can only be combined with integers of the same class, or scalar doubles.
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (4개)
KSSV
2022년 4월 14일
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
2022년 4월 14일
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
Bruno Luong
2022년 4월 14일
Add cast to double statement after reading your image
im=imread(' image.png');
im = double(im);
...
yanqi liu
2022년 4월 19일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!