how should i fix the problem :Index exceeds the number of array elements (4).
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clear;clc;
im=imread('unnamed.jpg');
im_1 = double(im);
R=im_1(:,:,1);
G=im_1(:,:,2);
B=im_1(:,:,3);
Max_r = max(max(R));
Max_g = max(max(G));
Max_b = max(max(B));
[row col]=size(im_1);
[r_y r_x]=find(im_1(:,:,1)==Max_r);
Numbers_1 = zeros(size(R));
Numbers_1(r_y,r_x) = R(r_y,r_x);
[g_y g_x]=find(im_1(:,:,2)==Max_g);
Numbers_2 = zeros(size(G));
Numbers_2(g_y,g_x) = G(g_y,g_x);
[b_y b_x]=find(im_1(:,:,3)==Max_b);
Numbers_3 = zeros(size(B));
Numbers_3(b_y,b_x) = B(b_y,b_x);
[a,b]=find(Numbers_1~=0 & Numbers_2~=0 & Numbers_3~=0);
Numbers_4 = zeros(size(B));
Numbers_4(a,b) = R(a,b);
%L=length(a);
%Y=zeros(L,1);
%for M=1:L
% Y(M)=(Max_r.^2.2+(1.5.*Max_g).^2.2+(0.6.*Max_b).^2.2/1+1.5^2.2+0.6^2.2).^(1/2.2); %Gamma校正法
%Y=0.299*Max_r + 0.587*Max_g + 0.114*Max_b;
%end
im = im2double(rgb2gray(im));
[~, T]=graythresh(im);
bwImage=imbinarize(im,T);
[label,num] = bwlabel(Numbers_2);
[M,~] = size(im);
%[label,num] = bwlabel(im);
coor = zeros(num,2);
for n = 1:num
[x,y] = find(label==n);
m_iN = length(x);
Y=zeros(m_iN,1);
for M=1:m_iN
Y(M)=(Max_r.^2.2+(1.5.*Max_g).^2.2+(0.6.*Max_b).^2.2/1+1.5^2.2+0.6^2.2).^(1/2.2); %Gamma校正法
%Y=0.299*Max_r + 0.587*Max_g + 0.114*Max_b;
for k = 1:m_iN
pSrc_1(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);
q=q';
S = q*pSrc_1';
S1 = S(1:5);
R1 = r(1:5,1:5);
C1 = R1\S1;
coor(n,:) = [-0.5*C1(3)/C1(1),-0.5*C1(4)/C1(2)];
end
pSrc_2(n) = Y(n);
matrix_B(n,1) = coor(n,1)^2;
matrix_B(n,2) = coor(n,2)^2;
matrix_B(n,3) = coor(n,1);
matrix_B(n,4) = coor(n,2);
matrix_B(n,5) = 1;
end
[q_2 r_2] = qr(matrix_B);
q_2 = q_2';
S2 = q_2*pSrc_2';
S2 = S2(1:5);
R2 = r_2(1:5,1:5);
C2 = R2\S2;
coor_2(:,:) = [-0.5*C2(3)/C2(1),-0.5*C2(4)/C2(2)];
0 comentarios
Respuestas (1)
Voss
el 18 de Abr. de 2022
I don't get that error (or any other errors) when I run it:
clear;clc;
im=imread('unnamed.jpg');
im_1 = double(im);
R=im_1(:,:,1);
G=im_1(:,:,2);
B=im_1(:,:,3);
Max_r = max(max(R));
Max_g = max(max(G));
Max_b = max(max(B));
[row col]=size(im_1);
[r_y r_x]=find(im_1(:,:,1)==Max_r);
Numbers_1 = zeros(size(R));
Numbers_1(r_y,r_x) = R(r_y,r_x);
[g_y g_x]=find(im_1(:,:,2)==Max_g);
Numbers_2 = zeros(size(G));
Numbers_2(g_y,g_x) = G(g_y,g_x);
[b_y b_x]=find(im_1(:,:,3)==Max_b);
Numbers_3 = zeros(size(B));
Numbers_3(b_y,b_x) = B(b_y,b_x);
[a,b]=find(Numbers_1~=0 & Numbers_2~=0 & Numbers_3~=0);
Numbers_4 = zeros(size(B));
Numbers_4(a,b) = R(a,b);
%L=length(a);
%Y=zeros(L,1);
%for M=1:L
% Y(M)=(Max_r.^2.2+(1.5.*Max_g).^2.2+(0.6.*Max_b).^2.2/1+1.5^2.2+0.6^2.2).^(1/2.2); %Gamma校正法
%Y=0.299*Max_r + 0.587*Max_g + 0.114*Max_b;
%end
im = im2double(rgb2gray(im));
[~, T]=graythresh(im);
bwImage=imbinarize(im,T);
[label,num] = bwlabel(Numbers_2);
[M,~] = size(im);
%[label,num] = bwlabel(im);
coor = zeros(num,2);
for n = 1:num
[x,y] = find(label==n);
m_iN = length(x);
Y=zeros(m_iN,1);
for M=1:m_iN
Y(M)=(Max_r.^2.2+(1.5.*Max_g).^2.2+(0.6.*Max_b).^2.2/1+1.5^2.2+0.6^2.2).^(1/2.2); %Gamma校正法
%Y=0.299*Max_r + 0.587*Max_g + 0.114*Max_b;
for k = 1:m_iN
pSrc_1(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);
q=q';
S = q*pSrc_1';
S1 = S(1:5);
R1 = r(1:5,1:5);
C1 = R1\S1;
coor(n,:) = [-0.5*C1(3)/C1(1),-0.5*C1(4)/C1(2)];
end
pSrc_2(n) = Y(n);
matrix_B(n,1) = coor(n,1)^2;
matrix_B(n,2) = coor(n,2)^2;
matrix_B(n,3) = coor(n,1);
matrix_B(n,4) = coor(n,2);
matrix_B(n,5) = 1;
end
[q_2 r_2] = qr(matrix_B);
q_2 = q_2';
S2 = q_2*pSrc_2';
S2 = S2(1:5);
R2 = r_2(1:5,1:5);
C2 = R2\S2;
coor_2(:,:) = [-0.5*C2(3)/C2(1),-0.5*C2(4)/C2(2)];
whos
Ver también
Categorías
Más información sobre Logical 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!