# "cleaning" a horizontal line removal code for object detection.

8 views (last 30 days)
Janrex Pensader on 22 Dec 2018
Commented: Image Analyst on 15 Jan 2019
I have a code that removes horizontal lines in an image but the problem is that it removes some of the lines that are needed for object detection. Any ide on how to make my output "cleaner"?
here is my code:
B=rgb2gray(A);
C=double(B);
for i=1:size(C,1)-2
for j=1:size(C,2)-2
Gx=( ( 2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2) ) - ( 2*C(i,j+1)+C(i,j)+C(i,j+2) ) );
%Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
if(Gx~=0)
B(i,j)=abs(Gx);
end
end
end
and here is my input image: and here is my output: Brian Hart on 22 Dec 2018
Hi Janrex,
For a nice clean image like this, there's a very simple solution. Just compute a row sum; rows with staff lines have a lower sum:
tmp=sum(C,2);
figure;plot(tmp) Now set those rows to white:
ind=find(tmp<1E5)
C(ind,:)=255;
figure;imagesc(C);axis image; (The downsampled image above doesn't look great; looks better for real)
If the white lines through the notes cause issues, you could do some morphology to close them (dilate then erode).
Image Analyst on 15 Jan 2019
Correct. You'd have to adjust it for each size image.

Image Analyst on 22 Dec 2018
Ditch that simplistic algorithm and go for one of the more robust algorithms published here: Algorithms on Musical Notation. I'm sure you'll find something much better.
##### 2 CommentsShowHide 1 older comment
Image Analyst on 28 Dec 2018
OK. Good for them. I'm sure they will learn a lot doing that. Not sure if any of the published papers I gave the link to do it that way since CNN's been around only for about 6 years or so. You might get a publication out of it if it's not been done before. Maybe you could at least upload it to the File Exchange.

R2018a

### Community Treasure Hunt

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

Start Hunting!