index out of bounds in matlab [closed] - matlab

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am not able to get how to run it, can anyone help me on this please.
I am receiving this error :
K>> [minutiae_valid]=postprocess_TICO(B,im,~K)
??? Attempted to access wind(273,386); index out of bounds because size(wind)=[368,385].
Error in ==> postprocess_TICO at 214
if (thinned(p,q)==1)&&(wind(p,q)==0)
postprocess_Tico
function [minutiae_valid]=postprocess_TICO(minutiae_valid,im1,thinned)
% clc;
% close all;
% clear all;
cell=16;%total no. of cells needed in quantization;
% im1= imread('E:\FINGERPRINT DATABASE\FVC2002\Dbs\Db1_a\16_6.tif');
wl=(33-1)/2;
% no=20;
% no2=20;
% nox = 0;
% noy = 0; %to choose border area
%
m=size(im1,1);
n=size(im1,2);
%m=(round(m/cell))*cell;
%n=(round(n/cell))*cell;
% im1=imresize(im1,[m n]);
% im=double(im1);
% figure;
% subplot(1,2,1);
% imshow(uint8(im));
% title('original input image');
%
% %Identify ridge-like regions and normalise image--------------------------
% blksze = 10;
% thresh =30;
% M0=100;
% STD0=150;
% [thinim, mask] = imgenhance(im, blksze, M0, STD0);
% subplot(1,2,2); subimage((thinim));
% title('Improved thinned input image', 'FontSize', 12);
% INPUT_IMG=thinim;
%
% %minutiae extraction
% thinned= INPUT_IMG;
% img = INPUT_IMG;
% [minutiae, minutiae_img, combined] = findminutiae(thinned, img);
% totminu_I = size(minutiae,1)
% figure,
% subplot(1,2,1), subimage(combined), title('minutiae before postprocess.')
% %______________________________________________________________
% %TO FIND BOUNDARY OF INPUT IMAGE AS WELL AS REGION OF FALSE MINU
% mask_input=mask;
% border=uint8(zeros(m,n));
%
% [m,n]=size(mask);
% validr=uint8(zeros(m,n));
% thin_temp=thinned;
% for i=1:m
% for j=2:n-1
% if((mask_input(i,j-1)==0)&&(mask_input(i,j)==1)&&(j<=n-no))
% border(i,j)=1;
% validr(i,j-nox:j+no)=1;
% thin_temp(i,j-nox:j+no)=1;
% end
%
% if ((mask_input(i,j+1)==0)&&(mask_input(i,j)==1)&&(j>no))
% border(i,j)=1;
% validr(i,j+nox:-1:j-no)=1;
% thin_temp(i,j+nox:-1:j-no)=1;
% end
%
% end
% end
%
% for i=1:m
% for j=1:n-1:n
% if (mask_input(i,j)==1)
% if (j==1)
% border(i,j)=1;
% validr(i,j:j+no)=1;
% thin_temp(i,j:j+no)=1;
% end
% if (j==n)
% border(i,j)=1;
% validr(i,j:-1:j-no)=1;
% thin_temp(i,j:-1:j-no)=1;
% end
% end
% end
% end
%
%
%
% for j=1:n
% for i=2:m-1
% if((mask_input(i-1,j)==0)&&(mask_input(i,j)==1)&&(i<=m-no))
% border(i,j)=1;
% validr(i-noy:i+no,j)=1;
% thin_temp(i-noy:i+no,j)=1;
% end
% if((mask_input(i+1,j)==0)&&(mask_input(i,j)==1)&&(i>no))
% border(i,j)=1;
% validr(i+noy:-1:i-no,j)=1;
% thin_temp(i+noy:-1:i-no,j)=1;
% end
%
% end
% end
%
% for j=1:n
% for i=1:m-1:m
% if (mask_input(i,j)==1)
% if (i==1)
% border(i,j)=1;
% validr(i:i+no,j)=1;
% thin_temp(i:i+no,j)=1;
% else validr(i:-1:i-no,j)=1;
% thin_temp(i:-1:i-no,j)=1;
% end
% end
% end
% end
%
% %___________________________________________________________________
% % removing minu at the border of roi
% for x=1:size(thinned,1)
% for y=1:size(thinned,2)
% if ((validr(x,y)==1)&&(thinned(x,y)==1))
% combined(x,y,:)=[255,255,255];
% minutiae_img(x,y,:)=[0,0,0];
%
% end
% end
% end
%
% for i=1:totminu_I
% x=minutiae(i,1);
% y=minutiae(i,2);
% if ((validr(x,y)==1)&&(thinned(x,y)==1))
% minutiae(i,:)=0;
% end
% end
% %__________________________
%
% subplot(1,2,2), subimage(combined), title('after boundary effect ')
% minu_count=1;
% minutiae_valid(minu_count, :) = [0,0,0,0]; %to make x, y, CN, theta value of minutiae not in border region.
% for i=1:totminu_I
% CN=minutiae(i,3);
% if (CN~=0)
% minutiae_valid(minu_count, :) = minutiae(i,:);
% minu_count = minu_count + 1;
% end
% end
% totminu_I= minu_count-1;
k=size(minutiae_valid);
totminu_I=k(1,1);
%FALSE RIDGE BIFURCATION
for i=1:totminu_I
if minutiae_valid(i,3)==3
wind=ones(m,n);
xi= minutiae_valid(i,1);
yi=minutiae_valid(i,2);
x=xi;
y=yi;
wind(xi-wl:xi+wl,yi-wl:yi+wl)=0; %window of size 25 cross 25
wind(xi,yi)=-1;
%mark '1', '2', '3'.
value=0;
r=x-1;
for c=y-1:y+1
if (thinned(r,c)==1)&&(wind(r,c)==0)
value=value+1;
wind(r,c)=value;
end
end
c=y+1;
for r=x-1:x+1
if (thinned(r,c)==1)&&(wind(r,c)==0)
value=value+1;
wind(r,c)=value;
end
end
r=x+1;
for c=y+1:-1:y-1
if (thinned(r,c)==1)&&(wind(r,c)==0)
value=value+1;
wind(r,c)=value;
end
end
c=y-1;
for r=x+1:-1:x-1
if (thinned(r,c)==1)&&(wind(r,c)==0)
value=value+1;
wind(r,c)=value;
end
end
for value=1:3 %search '1'/'2/'3' value pixel arond the minutia point in the window.
for p=x-1:x+1
for q=y-1:y+1
if wind(p,q)==value
xi=p;
yi=q;
end
end
end
cnt=0;
while(xi>x-wl)&&(xi<x+wl)&&(yi>y-wl)&&(yi<y+wl) %mark '1'/'2'/'3' to the adjacent connected pixels
k=0;
for p=xi-1:xi+1
for q=yi-1:yi+1
if (thinned(p,q)==1)&&(wind(p,q)==0)
wind(p,q)=value;
k=k+1;
if k==1
x1=p;
y1=q;
end
if k==2 %more than one connected pixel
cnt=cnt+1;
x2=p;
y2=q;
t1=x1;
x1=x2;
x2=t1;
t2=y1;
y1=y2;
y2=t2;
%___________
xi=x2;
yi=y2;
while(xi>x-wl)&&(xi<x+wl)&&(yi>y-wl)&&(yi<y+wl)
k=0;
flag_see=0;
for p=xi-1:xi+1
for q=yi-1:yi+1
if (thinned(p,q)==1)&&(wind(p,q)==0)
wind(p,q)=value;
flag_see=1;
x3=p;
y3=q;
k=k+1;
end
end
end
if(flag_see==1)
xi=x3;
yi=y3;
else
xi=p;
yi=q;
end
if k==0
break
end
end
% xi=x1;
% yi=y1;
end
end
end
end
xi=x1;
yi=y1;
if k==0
break
end
end
end
% figure,subimage(wind);
%to count 0-1, 0-2, 0-3 transition around the boundary clkwise
T=1;
for v=1:3
T0v=0;
r=x-wl;
for c=y-wl:y+(wl-1)
if (wind(r,c)==0)&&(wind(r,c+1)==v)
T0v=T0v+1;
end
end
c=y+wl;
for r=x-wl:x+(wl-1)
if (wind(r,c)==0)&&(wind(r+1,c)==v)
T0v=T0v+1;
end
end
r=x+wl;
for c=y+wl:-1:y-(wl-1)
if (wind(r,c)==0)&&(wind(r,c-1)==v)
T0v=T0v+1;
end
end
c=y-wl;
for r=x+wl:-1:x-(wl-1)
if (wind(r,c)==0)&&(wind(r-1,c)==v)
T0v=T0v+1;
end
end
T1=T0v==1;
T=T & T1;
end
if T~=1
minutiae_valid(i,:)=[0 0 0 0];
combined(x,y,:)=[255,255,255];
end
end
end
minu_count=1;
minutiae_valid_final(minu_count, :) = [0,0,0,0]; %to make x, y, CN, theta value of minutiae not in border region.
for i=1:totminu_I
CN = minutiae_valid(i,3);
if (CN~=0)
minutiae_valid_final(minu_count, :) = minutiae_valid(i,:);
minu_count = minu_count + 1;
end
end
% totminu_I= minu_count-1;
minutiae_valid = minutiae_valid_final;
% figure, subimage(combined);

At lines 212 and 213 you create nested loops that loop over nine elements of wind looking for elements that match some sort of condition. When you find one, you change the center of your nine element block.
The problem arises when the center of your block is on an edge of wind. When you look over the nine elements centered at an edge you must not access indices in the same way, otherwise you get the error as in above. To illustrate a simple case of this:
a = rand(4,4);
for p=2:4
for q = 1:3
tmp += a(p,q)
end
end
sums the 9 elements of a (a square array) centered at (3,2).
a = rand(4,4);
for p=3:5
for q = 1:3
tmp += a(p,q)
end
end
will generate the same error that you have when it tries to access a(5,1) because this element of the array does not exist. The correct way to fix this depends on what you're trying to do, but that's most definitely beyond the scope of your question, and our ability to figure out.
I hope this helps.
Echoing some of the comments, I'd like to offer you a piece of advice. In the future, you're much more likely to get on taget, quality answers if you can boil your question down to the shortest possible test case. This is also a valuable step in debugging your own code. Figuring out how to construct a test case will often make the answer to your problem apparent. When it's not apparent, Stackoverflow is an excellent resource.

Related

SeDuMi Matlab Code for Optimization problem

have this optimization Problem and need to implement this problem using SeDuMi Technique in MATLAB. Here, Q_i = h_i * h_i^(H). and h_i are randomly generated vector. I would like someone to help me with the matlab code for the implementation of this optimization problem in SeDuMi:
Matlab code, which i have been working on:
% % % % % % % % % % % % % % % % % % % % % % % % % % % % %
clear all; clc
N = 10; % Number of antennas # BS
M = 5; % Number of single antenna User
H = (randn(N,M) + 1j*randn(N,M)) *sqrt(0.5);
Q = zeros(N,N,M);
vecQs= [];
for k = 1:M
Q(:,:,k) =H(:,k)'*H(:,k);
vecQs = [vecQs,vec(Q(k).')];
end
A=[-eye(M),vecQs.'];
b=ones(M,1);
c=[zeros(M,1);vec(eye(N))];
K.l=M;
K.s=N;
K.scomplex=1;
[x_opt,y_opt,info]=sedumi(A,b,c,K);
Xopt=mat(x_opt(M+1:end));

Matlab: use plot and semilogy in same graph (Matlab 2014)

I want to use plot and semilog in the same graph so as to compare results. I get only the one waveform though using hold on function. What can I do ? I cant use yyaxis left cause my matlab is lower than 2016. Any help?
Here is my code:
figure
semilogy(VG, ID3)
hold on
plot(VG, ID3)
hold off
A possible solution to have both the linear and the semilog chart in the same graph could be to create two overlapping graphs:
on the first you can plot the data with the linear scale
on the second you can plot the data with the logarithmic scale either on the x or axis
The main steps are:
create a figure
create the first axes in the figure
set the color of the axes to the same color used for the data, this will help recognising the data
plot the data with plot
create the second axes in the figure and set its size equal to the one of the first axes (now the secon axes is the one "active")
move the X axis location to the top of the chart
move the Yaxis location to the right of the chart
plot the data with semilogy
set the color of the axes to the same color used for the data, this will help recognising the data
add the title, the legend and the x / y labels
Since we have changed the location of the X and Y axis of the second axes, we need to adjust the dimenisons of the figure and of the axes so thay fit toghter
Now you can fix the problem of the different grid of the two axes:
to do that, you can add a menu item to the menu bar (with the uimenu function) to toggle the grid
In the following, a possible implementation of the suggested approach.
Since you have not specified if you use R2014a or R014b, in the code below you can find both the way to set the properties of the figure and axes:
the "old" way: using get / set
the "new" one dot notation available from R2014b
(the last one is "commented")
% Define input data
x=linspace(0,30,30)
y=rand(30, 1);
% Cretate a Figure
f=figure('units','normalized')
% Create the first axes in the figure
ax1=axes
% Plot the data with "PLOT"
ph=plot(x,y,'r')
% Set the axis labeks
xlabel('X data')
ylabel('Y data, LIN mode')
% Get the position of the first axes
% % % % % % % % % % % % % % % % % % % % % % % % ax1_pos=ax1.Position
ax1_pos=get(ax1,'position')
% Set the color of the fist axes
% % % % % % % % % % % % % % % % % % % % % % % % ax1.XColor='r'
% % % % % % % % % % % % % % % % % % % % % % % % ax1.YColor='r'
set(ax1,'xcolor','r','ycolor','r')
% Add the second axes in the figure
ax2=axes('position',ax1_pos)
% Plot the data with SEMILOGY
slh=semilogy(x,y,'b')
% Set the ylabel
ylabel('Y data, LOG mode')
% Set the title of the chrt
title('Linear and Semilog Plot')
% Move the X axis location to the top of the chart
% % % % % % % % % % % % % % % % % % % % % % % % ax2.XAxisLocation='top'
set(ax2,'XAxisLocation','top')
% Move the XYaxis location to the right of the chart
% % % % % % % % % % % % % % % % % % % % % % % % ax2.YAxisLocation='right'
set(ax2,'YAxisLocation','right')
% Set the color of the second axes to transparent
% % % % % % % % % % % % % % % % % % % % % % % % % ax2.Color='none'
set(ax2,'color','none')
% Set the color of the second axes
% % % % % % % % % % % % % % % % % % % % % % % % % ax2.XColor='b'
% % % % % % % % % % % % % % % % % % % % % % % % % ax2.YColor='b'
set(ax2,'xcolor','b','ycolor','b')
% Add the lgend to the chart
legend([ph slh],'plot','semilogy','location','best')
% Adjust the size of the the first axes
% % % % % % % % % % % % % % % % % % % % % % % % ax1.Position=[ax1_pos(1) ax1_pos(2) ax1_pos(3)*.9 ax1_pos(4)*.9]
set(ax1,'position',[ax1_pos(1) ax1_pos(2) ax1_pos(3)*.9 ax1_pos(4)*.9])
% et the size of the second axes as per the first one
ax2.Position=ax1.Position
set(ax2,'position',[ax1_pos(1) ax1_pos(2) ax1_pos(3)*.9 ax1_pos(4)*.9])
% Adjust the size of the figure
% % % % % % % % % % % % % % % % % % % % % % % % % % % fp=f.Position
fp=get(f,'position')
% % % % % % % % % % % % % % % % % % % % % % % % % % % f.Position=[0.1,0.1,fp(3)*1.2,fp(4)*1.2]
set(f,'position',[0.1,0.1,fp(3)*1.2,fp(4)*1.2])
% Add the menu to manage the grid
mh=uimenu('Label','Grid manag.')
m1h=uimenu(mh,'Label','Linear Grid','callback', ...
'axes(ax1);grid;axes(ax2);if(strcmp(m1h.Checked,''off'')),m1h.Checked=''on'';else,m1h.Checked=''off'';end')
m2h=uimenu(mh,'Label','Log Grid','callback', ...
'axes(ax2);grid;if(strcmp(m2h.Checked,''off'')),m2h.Checked=''on'';else,m2h.Checked=''off'';end')
I often have to make figures comparing data in linear and log space. Stacking the plots using subplot() gives a nice visual. Example:
% set up dummy data that is evenly-space in logspace
x = 10.^((linspace(log10(.01), log10(10),20))');
y = rand(20, 1);
% finish setup
figure
subplot(2,1,1)
plot(x, y, 'DisplayName', 'MyData')
title('Plot with Linear Axes')
xlabel('X-Axis')
ylabel('Y-Axis')
grid on
set(legend, 'Location', 'best')
subplot(2,1,2)
semilogx(x, y, 'DisplayName', 'MyData')
title('Plot with LogX Axis')
xlabel('LogX-Axis')
ylabel('Y-Axis')
grid on
set(legend, 'Location', 'best')
The above produces this:

all the characters in number plate are not recognized

I am extracting and segmenting the characters from number plate.I am facing problems with character recognition. I wish to extract the number and symbol and do not consider about alphabets.I am getting one character as output out of eight. After running this code, i got answer is'1'. I am appending matlab code for location and segmentation of the plate. I have given the input image for the reference.`]5 []6[]7[]8Can anyone help me to rectify this error?
function [ImgPlate] = LocationPlate(I)
%% Cutting and resizing the original image %%
% I=imread('2222.jpg');
% figure,imshow(I);
[rows columns]=size(I);
columns=columns/3;
xmin=round(0.20*rows);
ymin=round(0.20*columns);
width=round((0.85*columns)-(0.10*columns));
height=round((0.85*rows)-(0.15*rows));
Io=imcrop(I,[xmin ymin width height]);
Io=imresize(Io,[480 640]);
Io=rgb2gray(Io);
Io=imadjust(Io);
%% Image processing to focus the area of number plate %%
%% Smooth edges and contours to delete characters.
se=strel('rectangle',[6 30]);
Ic=imclose(Io,se);
Ic=imadjust(Ic);
tophat=Ic-Io;
Ibw=(tophat>85);
%% Remove the related elements with fewer than 70 pixels %%
%% Remove objects that are not plate %%
plate= bwlabel(Ibw,4);
obj= max(max(plate));
dim1 = regionprops(plate, 'area')';
dim=[dim1.Area];
dim(find(dim<70))=0;
for i=1:obj
index=find(plate==i);
if dim(i)==0
plate(index)=0;
else
plate(index)=1;
end
end
CC=bwconncomp(plate);
P=regionprops(CC,'all');
[rp cp]=size(plate);
for i=1:CC.NumObjects
if P(i).MajorAxisLength>(2*cp/3)
plate(P(i).PixelIdxList(:,1))=0;
end
end
%% Remove objects that are not candidates for plate %%
se3=strel('rectangle',[30 70]);
r2=imclose(plate,se3);
se2=strel('rectangle',[5 30]);
r=imdilate(r2,se2);
CC=bwconncomp(r);
P=regionprops(CC,'all');
for i=1:CC.NumObjects
if P(i).MajorAxisLength>(2*cp/3)
r(P(i).PixelIdxList(:,1))=0;
end
end
%% select the largest connected component after preprocessing, the
%%plate
plate1= bwlabel(r,4);
dim2= regionprops(plate1, 'area')';
dim1=[dim2.Area];
f=max(dim1);
indMax=find(dim1==f);
plate1(find(plate1~=indMax))=0;
%% cutting of original image %%
[cuty, cutx] = find( plate1 > 0);
up = min(cuty);
down = max(cuty);
left = min(cutx);
right = max(cutx);
img_cut_v = Io(up:down,:,:);
img_cut_h = img_cut_v(:,left:right,:);
ImgPlate = img_cut_h;
%% different mask for location plate %%
[r c]=size(ImgPlate);
if r<25 || r>65
[rows columns]=size(I);
columns=columns/3;
xmin=round(0.20*rows);
ymin=round(0.20*columns);
width=round((0.85*columns)-(0.10*columns));
height=round((0.85*rows)-(0.15*rows));
Io=imcrop(I,[xmin ymin width height]);
Io=imresize(Io,[480 640]);
Io=rgb2gray(Io);
Io=imadjust(Io);
se=strel('rectangle',[6 30]);
Ic=imclose(Io,se);
Ic=imadjust(Ic);
tophat=Ic-Io;
Ibw1=(tophat>85);
mask=zeros(480,640);
for i=40:370
for j=40:575
mask(i,j)=1;
end
end
Ibw=Ibw1 & im2bw(mask);
plate= bwlabel(Ibw,4);
obj= max(max(plate));
dim1 = regionprops(plate, 'area')';
dim=[dim1.Area];
dim(find(dim<70))=0;
for i=1:obj
index=find(plate==i);
if dim(i)==0
plate(index)=0;
else
plate(index)=1;
end
end
CC=bwconncomp(plate);
P=regionprops(CC,'all');
[rp cp]=size(plate);
for i=1:CC.NumObjects
if P(i).MajorAxisLength>(cp/3)
plate(P(i).PixelIdxList(:,1))=0;
end
end
se3=strel('rectangle',[30 70])
r2=imclose(plate,se3);
se2=strel('rectangle',[5 30]);
r=imdilate(r2,se2);
plate1= bwlabel(r,4);
dim2= regionprops(plate1, 'area')';
dim1=[dim2.Area];
f=max(dim1);
indMax=find(dim1==f);
plate1(find(plate1~=indMax))=0;
[cuty, cutx] = find( plate1 > 0);
up = min(cuty);
down = max(cuty);
left = min(cutx);
right = max(cutx);
img_cut_v = Io(up:down,:,:);
img_cut_h = img_cut_v(:,left:right,:);
ImgPlate = img_cut_h;
end
%% Representation %%
% figure(1);
% imshow(I);
% subplot(2,2,1);imshow(I);
% subplot(2,2,2);imshow(Ic);% subplot(2,2,3);imshow(plate);
% subplot(2,2,4);imshow(plate1);
figure(2); imshow(img_cut_h);title('output location plate');
end
function [Objects,ImgChar]=Segmentation(ImgPlate)
%% Binarize the image %%
level = graythresh(ImgPlate);
Ibw =(im2bw(ImgPlate,level));
%% Select the orientation of the largest object in the image.
%% Turn this angle at the picture.
%% Plate cutting to segment the characters that compose %%
Fl=bwlabel(Ibw);
Statsbf=regionprops(Fl,'all');
Flmax=find([Statsbf.Area]==max([Statsbf.Area]));
angle=Statsbf(Flmax).Orientation;
F2=imrotate(Fl,-angle);
L=bwlabel(F2);
Statsbf=regionprops(L,'all');
maxi=find([Statsbf.Area]==max([Statsbf.Area]));
BB=Statsbf(maxi).BoundingBox;
F2=imcrop(F2,[BB(1,1) BB(1,2) BB(1,3) BB(1,4)]);
% figure,imshow(F2);
%% First three and last three rows to zero.
%% First two and last two columns to zero.
%% So remove connectivity between characters and background %%
%% Remove small impurities %%
L4=not(F2);
[r c]=size(L4);
L4(1,:)=0;
L4(2,:)=0;
L4(3,:)=0;
L4(r,:)=0;
L4(r-1,:)=0;
L4(r-2,:)=0;
L4(:,1)=0;
L4(:,2)=0;
L4(:,c)=0;
L4(:,c-1)=0;
L4b=bwlabel(L4);
Stats3=regionprops(L4b,'all');
sarea3=[Stats3.Area];
G=find(sarea3<70);
for cv=1:length(G)
G1=find(L4b==G(cv));
L4(G1)=0;
end
[r c]=size(L4);
CC=bwconncomp(L4);
L=bwlabel(L4);
ind2=max(L(:,c-2));
P=regionprops(CC,'all');
%% Remove objects smaller and larger than a character %%
i=1;
if (max(P(i,1).PixelList(:,1))-min(P(i,1).PixelList(:,1)))<(c/13)
L4(CC.PixelIdxList{1,i})=0;
end
for i=1:CC.NumObjects
if (max(P(i,1).PixelList(:,1))-min(P(i,1).PixelList(:,1)))>(2*c/3)
L4(CC.PixelIdxList{1,i})=0;
end
if (max(P(i,1).PixelList(:,2))-min(P(i,1).PixelList(:,2)))<(r/3)
L4(CC.PixelIdxList{1,i})=0;
end
if (max(P(i,1).PixelList(:,1))-min(P(i,1).PixelList(:,1)))<(c/8)
L4(find(L==ind2))=0;
end
end
L4=imclose(L4,strel('disk',1));
L4=imopen(L4,strel('disk',1));
% figure(4);
imshow(L4);
L4b=bwlabel(L4);
Stats3b=regionprops(L4b,'all');
N=length(Stats3b);
while N>8
L4=imdilate(L4,strel('disk',1));
L4b=bwlabel(L4);
Stats3b=regionprops(L4b,'all');
N=length(Stats3b);
end
L4b=bwlabel(L4);
Stats3b=regionprops(L4b,'all');
ImgChar=zeros(100,100,N);
%% Dividing characters which are connected %%
%% Remove objects that have been listed as characters but are not%
%% Show every character in the correct position %%
cont=0;
cont1=0;
for i=1:N
[r1 c1]=size(Stats3b(i,1).Image);
if c1>round(c/6)
cont1=cont;
Stats3b(i,1).Image(:,round(c1/2))=0;
L5=Stats3b(i,1).Image;
CC=bwconncomp(L5);
CC1=regionprops(CC,'all');
for j=1:CC.NumObjects
[r2 c2]=size(CC1(j,1).Image);
if c2>round(c/7)
CC1(j,1).Image(:,round(c2/2))=0;
L6=CC1(j,1).Image;
LL=bwconncomp(L6);
CC2=regionprops(LL,'all');
for k=1:LL.NumObjects
CC2(k).Image=imresize(CC2(k).Image, [100 100]);
figure;imshow((CC2(k).Image))
ImgChar(:,:,i+cont1)=not(CC2(k).Image);
cont1=cont1+1;
end
cont=cont+1;
else
CC1(j).Image=imresize(CC1(j).Image, [100 100]);
figure;imshow((CC1(j).Image))
ImgChar(:,:,i+cont1)=not(CC1(j).Image);
cont1=cont1+1;
end
end
cont=cont+1;
else
Stats3b(i).Image=imresize(Stats3b(i).Image, [100 100]);
figure;imshow((Stats3b(i).Image));
if cont~=0
ImgChar(:,:,i+cont)=not(Stats3b(i).Image);
else
ImgChar(:,:,i)=not(Stats3b(i).Image);
end
end
end
%% Remove spurious %%
[x, y, Objects]=size(ImgChar);
end
function [strPlate] = Recognition(I)
I=imread('2222.jpg');
[ImgPlate] = LocationPlate(I);
[Objects,ImgChar]=Segmentation(ImgPlate);
N=struct('Image',{});
numbers={'0','1','2','3','4','5','sign'};
N(1).Image=imresize(im2bw(uint8(imread('untitled0.bmp'))),[100 100]);
N(2).Image=imresize(im2bw(uint8(imread('untitled1.bmp'))),[100 100]);
N(3).Image=imresize(im2bw(uint8(imread('untitled2.bmp'))),[100 100]);
N(4).Image=imresize(im2bw(uint8(imread('untitled3.bmp'))),[100 100]);
N(5).Image=imresize(im2bw(uint8(imread('untitled4.bmp'))),[100 100]);
N(6).Image=imresize(im2bw(uint8(imread('untitled5.bmp'))),[100 100]);
N(7).Image=imresize(im2bw(uint8(imread('sign.jpg'))),[100 100]);
if Objects==8
strPlate=[];
for i=1:Objects
char=ImgChar(:,:,i);
if (i==2)||(i==3)||(i==4) || (i==5) || (i==6)||(i==7) ||(i==8)
list_corr=[];
for j=1:7
corr=corr2(N(j).Image,char);
list_corr=[list_corr corr];
end
f=max(list_corr);
maxcorr=find(list_corr==f);
strPlate=[strPlate numbers(maxcorr)];
end
end
end
end
I find you compare char image with the default value of ImgChar (zeros). I discovered this by add imshow(char) as you can see in the below code.
for i=1:Objects
char=ImgChar(:,:,i);
if (i==2)||(i==3)||(i==4) || (i==5) || (i==6)||(i==7) ||(i==8)
list_corr=[];
for j=1:6
corr=corr2(N(j).Image,char);
list_corr=[list_corr corr];
end
close all
figure;imshow(char)
f=max(list_corr);
maxcorr=find(list_corr==f);
strPlate=[strPlate numbers(maxcorr)];
end
end
To correct the above error, I modified the below code to store images in ImgChar. this line maybe not correct but I believe my answer may help you.
Stats3b(i).Image=imresize(Stats3b(i).Image, [100 100]);
figure;
imshow((Stats3b(i).Image));
ImgChar(:,:,i) = Stats3b(i).Image;% added
if cont~=0
else
ImgChar(:,:,i)=not(Stats3b(i).Image);
end

bin2mat running slow need a faster solution

I am using bin2mat function from matlab file exchange, for some reason it runs very slow. Is it possible to make it run faster or is there an alternative? I am trying: zC = bin2mat(s.X,s.Y,s.Z,xC,yC); I am not sure where it gets bogged down. I need to do this on point cloud data to calculate volume and such.
Here is the code:
function ZG = bin2mat(x,y,z,XI,YI,varargin)
% BIN2MAT - create a matrix from scattered data without interpolation
%
% ZG = BIN2MAT(X,Y,Z,XI,YI) - creates a grid from the data
% in the (usually) nonuniformily-spaced vectors (x,y,z)
% using grid-cell averaging (no interpolation). The grid
% dimensions are specified by the uniformily spaced vectors
% XI and YI (as produced by meshgrid).
%
% ZG = BIN2MAT(...,#FUN) - evaluates the function FUN for each
% cell in the specified grid (rather than using the default
% function, mean). If the function FUN returns non-scalar output,
% the output ZG will be a cell array.
%
% ZG = BIN2MAT(...,#FUN,ARG1,ARG2,...) provides aditional
% arguments which are passed to the function FUN.
%
% EXAMPLE
%
% %generate some scattered data
% [x,y,z]=peaks(150);
% ind=(rand(size(x))>0.9);
% xs=x(ind); ys=y(ind); zs=z(ind);
%
% %create a grid, use lower resolution if
% %no gaps are desired
% xi=min(xs):0.25:max(xs);
% yi=min(ys):0.25:max(ys);
% [XI,YI]=meshgrid(xi,yi);
%
% %calculate the mean and standard deviation
% %for each grid-cell using bin2mat
% Zm=bin2mat(xs,ys,zs,XI,YI); %mean
% Zs=bin2mat(xs,ys,zs,XI,YI,#std); %std
%
% %plot the results
% figure
% subplot(1,3,1);
% scatter(xs,ys,10,zs,'filled')
% axis image
% title('Scatter Data')
%
% subplot(1,3,2);
% pcolor(XI,YI,Zm)
% shading flat
% axis image
% title('Grid-cell Average')
%
% subplot(1,3,3);
% pcolor(XI,YI,Zs)
% shading flat
% axis image
% title('Grid-cell Std. Dev.')
%
% SEE also RESHAPE ACCUMARRAY FEVAL
% A. Stevens 3/10/2009
% astevens#usgs.gov
%check inputs
error(nargchk(5,inf,nargin,'struct'));
%make sure the vectors are column vectors
x = x(:);
y = y(:);
z = z(:);
if all(any(diff(cellfun(#length,{x,y,z}))));
error('Inputs x, y, and z must be the same size');
end
%process optional input
fun=#mean;
test=1;
if ~isempty(varargin)
fun=varargin{1};
if ~isa(fun,'function_handle');
fun=str2func(fun);
end
%test the function for non-scalar output
test = feval(fun,rand(5,1),varargin{2:end});
end
%grid nodes
xi=XI(1,:);
yi=YI(:,1);
[m,n]=size(XI);
%limit values to those within the specified grid
xmin=min(xi);
xmax=max(xi);
ymin=min(yi);
ymax=max(yi);
gind =(x>=xmin & x<=xmax & ...
y>=ymin & y<=ymax);
%find the indices for each x and y in the grid
[junk,xind] = histc(x(gind),xi);
[junk,yind] = histc(y(gind),yi);
%break the data into a cell for each grid node
blc_ind=accumarray([yind xind],z(gind),[m n],#(x){x},{NaN});
%evaluate the data in each grid using FUN
if numel(test)>1
ZG=cellfun(#(x)(feval(fun,x,varargin{2:end})),blc_ind,'uni',0);
else
ZG=cellfun(#(x)(feval(fun,x,varargin{2:end})),blc_ind);
end
It is slower on these two steps for one run it took:
ZG=cellfun(#(x)(feval(fun,x,varargin{2:end})),blc_ind); took 33 secs
blc_ind=accumarray([yind xind],z(gind),[m n],#(x){x},{NaN}); took 10 secs
You can change blc_ind = ... to
ZG=accumarray([yind xind],z(gind),[m n],#mean,NaN);
and delete other codes form here so the is no need to if numel(test)>1....

Undefined function 'qquadrature' for input arguments of type 'double'

I'm a new user of Matlab, can you please help:
I have the following code in an .M file:
`% free vibration of non-prismatic Euler beams with or without axial load
%using differential quadrature method
clc;
ne=50;
n=ne+1;
nn=2*n;
no=4;
m=zeros(n,1);
x=zeros(n,1);
xi=zeros(n,1);
c=zeros(n,n,no);
d=zeros(n+4,n+4);
e=zeros(n+4,n+4);
z=zeros(n+4,1);
f=zeros(n+4,1);
alp=zeros(n,n);
bet=zeros(n,n);
zz=zeros(n,1);
ki=zeros(n,n);
eta=zeros(n,n);
const=1.0;
l=12;
ymod=200e09;
rho=7800;
format long;
for i=1:n
xi(i)=0.5*(1-cos((i-1)*pi/ne));
%mi(i)=0.000038*(1-xi(i)^2/2);
ar(i)=1/rho;
mi(i)=0.000038;
ki(i,i)=ymod*mi(i);
end
c=qquadrature(xi,n,no);
%c = harquadrature(xi,n,no)
for i = 1:n
alp(i,i) = 0;
bet(i,i) = 0;
for j = 1:n
alp(i,i) = alp(i,i)+c(i,j,1)*ki(j,j)/l;
bet(i,i) = bet(i,i)+c(i,j,2)*ki(j,j)/l^2;
end
end
d=zeros(n+4,n+4);
% free vibration of the beam
% axial load on the beam t=+ if it is compressive t=- if it is tensile
% weight of the beam / unit length
t=520895.0;
d(1:n,1:n)=2.0*alp*c(:,:,3)/l^3+bet*c(:,:,2)/l^2+ki*c(:,:,4)/l^4+eta+t*c(:,:,2)/l^2;
% boundary conditions
% clamped - free
% d(n+1,1)=1.0;
% d(n+2:n+2,1:n)=alp(n,n)*c(n,1:n,2)/l^2+ki(n,n)*c(n,1:n,3)/l^3+t*c(n,1:n,1)/l;
% d(n+3:n+3,1:n)=c(1,1:n,1)/l;
% d(n+4:n+4,1:n)=ki(n,n)*c(n,1:n,2)/l^2;
% d(1,n+1)=1.0;
% for i=1:n
% d(i,n+2)=d(n+2,i);
% d(i,n+3)=d(n+3,i);
% d(i,n+4)=d(n+4,i);
% end
% pinned - pinned
d(n+1,1)=1.0;
d(n+2:n+2,1:n)=ki(n,n)*c(n,1:n,2)/l^2;
d(n+3:n+3,1:n)=ki(1,1)*c(1,1:n,2)/l^2;
d(n+4,n)=1.0;
d(n,n+4)=1.0;
d(1,n+1)=1.0;
d(n+4,n)=1.0;
for i = 1:n
d(i,n+2)=d(n+2,i);
d(i,n+3)=d(n+3,i);
end
e=zeros(n+4,n+4);
for i=1:n
e(i,i)=rho*ar(i);
end
z=d\e;
[ev,euv]=eig(z);
for i=1:n
zz(z)=ev(i,5);
end
omega=sqrt(1/euv(5,5));
sprintf(' natural frequency\n')
omega;
figure(1);
plot(xi,zz)
xlabel(' x/L ')
ylabel(' z')
title (' fundamental mode shape ')`
I have stored this file (Untitled.M) in the normal Matlab path, and therefore I'm assuming that Matlab will read the function when it's starting and that this function therefore should be available to use.
Then I am trying to run this single M-files.
But "Undefined function 'qquadrature' for input arguments of type 'double'" message appears..
Can somebody show me where's the problem and how ti fix it?
Thankyou..