how should i fix the problem :Index exceeds the number of array elements (4).

1 visualización (últimos 30 días)
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)];

Respuestas (1)

Voss
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
Name Size Bytes Class Attributes B 2937x2278 53523888 double C1 5x1 40 double C2 5x1 40 double G 2937x2278 53523888 double M 1x1 8 double Max_b 1x1 8 double Max_g 1x1 8 double Max_r 1x1 8 double Numbers_1 2937x2278 53523888 double Numbers_2 2937x2278 53523888 double Numbers_3 2937x2278 53523888 double Numbers_4 2937x2278 53523888 double R 2937x2278 53523888 double R1 5x5 200 double R2 5x5 200 double S 504x1 4032 double S1 5x1 40 double S2 5x1 40 double T 1x1 8 double Y 24x1 192 double a 88x1 704 double b 88x1 704 double b_x 26x1 208 double b_y 26x1 208 double bwImage 2937x2278 6690486 logical col 1x1 8 double coor 12x2 192 double coor_2 1x2 16 double g_x 213x1 1704 double g_y 213x1 1704 double im 2937x2278 53523888 double im_1 2937x2278x3 160571664 double k 1x1 8 double label 2937x2278 53523888 double m_iN 1x1 8 double matrix_B 12x5 480 double n 1x1 8 double num 1x1 8 double pSrc_1 1x504 4032 double pSrc_2 1x12 96 double q 504x504 2032128 double q_2 12x12 1152 double r 504x5 20160 double r_2 12x5 480 double r_x 6675x1 53400 double r_y 6675x1 53400 double row 1x1 8 double tmp_B 504x5 20160 double x 24x1 192 double y 24x1 192 double

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by