hi im trying to get the vertical profiling of a braille document but im getting this kind of error..help will be much appreciated..the error is at the end of the line of codes..thankyou so much!

1 view (last 30 days)
%vertical profiling
yProfile = mean('z'); %peak profile
ac = xcov(yProfile); %cross correlation
p1 = diff(ac([1 1:end]));
p2 = diff(ac([1:end end]));
maxima = find(p1>0 & p2<0); %peak locations
estPeriod = round(median(diff(maxima))) %spacing estimate
seLine = strel('line',estPeriod,0);
yProfile2 = imtophat(yProfile,seLine); %background removed
level = graythresh(yProfile2/255); %automatic threshold level
bw = im2bw(yProfile2/255,level); %binarized peak regions
L = bwlabel(bw); %labeled regions
stats = regionprops(L);
centroids = [stats.Centroid]; %centroids
yCenters = centroids(1:2:end) %Y parts only
gap = diff(yCenters)/2; %inner region half widths
first = yCenters(1)-gap(1);
% list defining vertical boundaries between spot regions
yGrid = round([first yCenters(1:end)+gap([1:end end])])
estPeriod =
NaN
yCenters =
1
Attempted to access gap(1); index out of bounds because
numel(gap)=0.

Answers (1)

Walter Roberson
Walter Roberson on 17 Dec 2015
What are you expecting
yProfile = mean('z'); %peak profile
to do?
What it is going to do is return the average value out of the character vector that contains the literal string 'z'. That character vector is only one element long so the mean() of it is the same as its numeric value, double('z') which is the scalar 122.
Everything else in your code falls apart because it is a scalar rather than a non-constant image.

Community Treasure Hunt

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

Start Hunting!