Image linescan consisting of sum of 3 pixels

I am trying to perform a linescan thru the centre of an image. I use the following to do this:
img=getimage(handles.axes1);
r=size(img,1)
c=size(img,2)
rMiddle=round(r/2)
cMiddle=round(c/2)
%Get linescan thru centre of image
yth_row=img(rMiddle,:);
xth_col=img(:,cMiddle);
%Plot the linescan on axes 2.
axes(handles.axes2)
cla
hold on;
x1=linspace(1,r+1,r);
x2=linspace(1,c+1,c);
plot(yth_row,'r','LineWidth',0.5)
plot(xth_col,'g','LineWidth',0.5)
grid on
hold off
I get the following (ignore the black plot lines)
However, the two line plots don't always go through the centre of the objects so I want to increase the thickness of the line plot so that it sums 3 pixels in the orthogonal direction to the line scan.
So something like:
yth_row=img(rMiddle,:)+img(rMiddle-1,:)+img(rMiddle+1,:)
xth_col=img(:,cMiddle)+img(:,cMiddle-1)+img(:,cMiddle+1);
Was wondering if there was a simpler/more elegant way so if I want to change to the mean I can easily do it.

Answers (0)

Categories

Find more on Descriptive Statistics and Insights in Help Center and File Exchange

Asked:

on 2 Nov 2015

Edited:

on 2 Nov 2015

Community Treasure Hunt

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

Start Hunting!