Index exceeds the number of array elements
2 ビュー (過去 30 日間)
表示 古いコメント
How to solve this?
Index exceeds the number of array elements (1208).
Error in Tablica (line 53)
if suma(i)== 0
回答 (2 件)
Yusuf Suer Erdem
2021 年 11 月 29 日
Hi could you try these codes?
close all;
clear;
clc;
format long g;
format compact;
im1 = imread('a.jpg'); %wczytanie obrazu
%%figure(1); imshow(im1)
im2 = rgb2gray(im1); %zmiana koloru
%%figure(2); imshow(im2)
im3 = imbinarize(im2); % binaryzacja obrazu
%%figure(3); imshow(im3)
im4 = edge(im2, 'prewitt'); %znalezienie krawedzi
%%figure(4); imshow(im4)
%odnalezienie tablicy rejestracyjnej
Iprops=regionprops(im4,'BoundingBox','Area', 'Image');
area = Iprops.Area;
count = numel(Iprops);
maxa= area;
boundingBox = Iprops.BoundingBox;
for i=1:count
if maxa<Iprops(i).Area
maxa=Iprops(i).Area;
boundingBox=Iprops(i).BoundingBox;
end
end
im = imresize(im4, [240 NaN]);
im = imopen(im, strel('rectangle', [4 4]));
im = imcrop(im3, boundingBox);%wyciecie tablicy
%%figure(5); imshow(im)
im = bwareaopen(~im, 1000); %usuniece obiektow jesli szerokosc jest za dluga lub za krotka niz 500
im_neg = imcomplement(im);
figure(6), imshowpair(im,im_neg,'montage');
labeledImage= bwlabel(im);
propied=regionprops(labeledImage,'BoundingBox');
im = imresize(im_neg, [240 NaN]);
im = imopen(im, strel ('rectangle', [4 4]));
im = bwareaopen(~im, 1000);
figure(34), imshow(im);
figure(7), imshow(im_neg), title ('Tablica');
[wiersz, kolumna] = size(im);
i=1;
suma=sum(im);
while i<84
if suma(1:i)== 0
p_kolumna = i;
break;
end
i=i+1;
end
p_kolumna = i;
im = [p_kolumna,1,kolumna,wiersz];
im_neg = imcrop(im_neg, [p_kolumna,1,kolumna,wiersz]);
I3 = ~im_neg;
I4 = sum(I3,1);
I5 = (I4>1);
tabhist=(1:1:size(im,2));
figure(9), imshow(im_neg), title ('Tablica');
figure (10), plot(tabhist)
figure(11), plot(I5)
ylim([0 2]);
yanqi liu
2021 年 11 月 30 日
clc
clear all
close all
format long g;
format compact;
im1 = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/817374/obraz_2021-11-29_164610.png'); %wczytanie obrazu
im1 = imcrop(im1, [20 148 481 85]);
%%figure(1); imshow(im1)
im2 = rgb2gray(im1); %zmiana koloru
%%figure(2); imshow(im2)
im3 = imbinarize(im2); % binaryzacja obrazu
%%figure(3); imshow(im3)
im4 = edge(im2, 'prewitt'); %znalezienie krawedzi
%%figure(4); imshow(im4)
%odnalezienie tablicy rejestracyjnej
Iprops=regionprops(im4,'BoundingBox','Area', 'Image');
area = Iprops.Area;
count = numel(Iprops);
maxa= area;
boundingBox = Iprops.BoundingBox;
for i=1:count
if maxa<Iprops(i).Area
maxa=Iprops(i).Area;
boundingBox=Iprops(i).BoundingBox;
end
end
im = imresize(im4, [240 NaN]);
im = imopen(im, strel('rectangle', [4 4]));
im = im3;%wyciecie tablicy
%%figure(5); imshow(im)
im = bwareaopen(~im, 1000); %usuniece obiektow jesli szerokosc jest za dluga lub za krotka niz 500
im_neg = imcomplement(im);
figure(6), imshowpair(im,im_neg,'montage');
labeledImage= bwlabel(im);
propied=regionprops(labeledImage,'BoundingBox');
im = imresize(im_neg, [240 NaN]);
im = imopen(im, strel ('rectangle', [4 4]));
im = bwareaopen(~im, 1000);
figure(34), imshow(im);
figure(7), imshow(im_neg), title ('Tablica');
[wiersz, kolumna] = size(im);
i=1;
suma=sum(im_neg);
while 1
if suma(i)== 0 || i >= size(im_neg,2)-1
p_kolumna = i;
break;
end
i=i+1;
end
p_kolumna = i;
im_neg = imcrop(im_neg, [1,1,p_kolumna-1,size(im_neg,1)-1]);
I3 = ~im_neg;
I4 = sum(I3,1);
I5 = sum(im_neg,1)>5;
tabhist=(1:1:size(im_neg,2));
figure(9), imshow(im_neg), title ('Tablica');
figure (10), plot(tabhist,I5); ylim([0 2])
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!