Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to blacken the center of a whole note?

Subject: how to blacken the center of a whole note?

From: Angelo

Date: 23 Aug, 2010 13:42:04

Message: 1 of 13

Hi, i'm doing an optical music recognition related program. i have to identity each musical notes in a music sheet. as of now, i have detected the quarter, eighth, and sixteenth notes by getting the centroid of each note. now, i am having problems in detecting hollow notes (whole and half notes) because they don't have centroids. my plan right now is to fill those two notes so that i can detect its centroid.

can you teach me on how to fill those notes? or can you give any better suggestions?

Subject: how to blacken the center of a whole note?

From: Sean

Date: 23 Aug, 2010 13:51:05

Message: 2 of 13

"Angelo " <kuyagerms_07@yahoo.com> wrote in message <i4ttrc$jmh$1@fred.mathworks.com>...
> Hi, i'm doing an optical music recognition related program. i have to identity each musical notes in a music sheet. as of now, i have detected the quarter, eighth, and sixteenth notes by getting the centroid of each note. now, i am having problems in detecting hollow notes (whole and half notes) because they don't have centroids. my plan right now is to fill those two notes so that i can detect its centroid.
>
> can you teach me on how to fill those notes? or can you give any better suggestions?

One way to fill the holes would be:
>>imfill(I, 'holes')
of course you would have to mask only the note you care about. I also don't understand what you mean when you say that "hollow notes (whole and half notes) because they don't have centroids."
They have centroids you might just not be understanding centroid properly..

Subject: how to blacken the center of a whole note?

From: Angelo

Date: 24 Aug, 2010 16:35:05

Message: 3 of 13

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i4tuc9$of2$1@fred.mathworks.com>...
> "Angelo " <kuyagerms_07@yahoo.com> wrote in message <i4ttrc$jmh$1@fred.mathworks.com>...
> > Hi, i'm doing an optical music recognition related program. i have to identity each musical notes in a music sheet. as of now, i have detected the quarter, eighth, and sixteenth notes by getting the centroid of each note. now, i am having problems in detecting hollow notes (whole and half notes) because they don't have centroids. my plan right now is to fill those two notes so that i can detect its centroid.
> >
> > can you teach me on how to fill those notes? or can you give any better suggestions?
>
> One way to fill the holes would be:
> >>imfill(I, 'holes')
> of course you would have to mask only the note you care about. I also don't understand what you mean when you say that "hollow notes (whole and half notes) because they don't have centroids."
> They have centroids you might just not be understanding centroid properly..

sorry for that, i'm new in matlab. anyway, thanks for the suggestion, i finally did it! now my only problem is how to detect the dot beside the note in this image:

http://tinyurl.com/26deuzj

Subject: how to blacken the center of a whole note?

From: ImageAnalyst

Date: 24 Aug, 2010 16:46:39

Message: 4 of 13

You can detect hollow notes via the Euler Number, and probably via the
area of the "ball" part as well.

How are you removing the lines? A morphological opening perhaps?
Make sure you use the correct structuring element so you don't get rid
of the "upright" connecting the ball to the flag (or whatever it's
called, sorry I don't know the names of the parts of the musical
notes). Or perhaps you used a tophat filter?

Subject: how to blacken the center of a whole note?

From: Angelo

Date: 24 Aug, 2010 18:56:24

Message: 5 of 13

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <74f352c7-f6fa-4602-aa94-2389605fcade@l6g2000yqb.googlegroups.com>...
> You can detect hollow notes via the Euler Number, and probably via the
> area of the "ball" part as well.
>
> How are you removing the lines? A morphological opening perhaps?
> Make sure you use the correct structuring element so you don't get rid
> of the "upright" connecting the ball to the flag (or whatever it's
> called, sorry I don't know the names of the parts of the musical
> notes). Or perhaps you used a tophat filter?

i removed the lines by doing an xor with the original binary image and the detected lines via bwconncomp.

how can i detect hollow notes with the Euler Number?

Subject: how to blacken the center of a whole note?

From: ImageAnalyst

Date: 24 Aug, 2010 19:55:17

Message: 6 of 13

On Aug 24, 2:56 pm, "Angelo " <kuyagerms...@yahoo.com> wrote:
> i removed the lines by doing an xor with the original binary image and the detected lines via bwconncomp.

I'm not sure how that would work, since bwconncomp just uses the same
"original binary image".

> how can i detect hollow notes with the Euler Number?

Euler number is basically how many holes there are in the object. It
is measured by regionprops:
"'EulerNumber' — Scalar that specifies the number of objects in the
region minus the number of holes in those objects. This property is
supported only for 2-D input label matrices. regionprops uses 8-
connectivity to compute the EulerNumber measurement."

Subject: how to blacken the center of a whole note?

From: Angelo

Date: 5 Sep, 2010 13:33:06

Message: 7 of 13

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e28a5413-3fa0-4a2a-86e3-c67c426b68e0@q22g2000yqm.googlegroups.com>...
> On Aug 24, 2:56 pm, "Angelo " <kuyagerms...@yahoo.com> wrote:
> > i removed the lines by doing an xor with the original binary image and the detected lines via bwconncomp.
>
> I'm not sure how that would work, since bwconncomp just uses the same
> "original binary image".
>
> > how can i detect hollow notes with the Euler Number?
>
> Euler number is basically how many holes there are in the object. It
> is measured by regionprops:
> "'EulerNumber' — Scalar that specifies the number of objects in the
> region minus the number of holes in those objects. This property is
> supported only for 2-D input label matrices. regionprops uses 8-
> connectivity to compute the EulerNumber measurement."

i already removed the staff lines in a music sheet. the problem is, a part of a hollow note was also removed causing me to have problems in getting the blobs. how can i restore the note?

Subject: how to blacken the center of a whole note?

From: ImageAnalyst

Date: 5 Sep, 2010 13:41:04

Message: 8 of 13

On Sep 5, 9:33 am, "Angelo " <kuyagerms...@yahoo.com> wrote:
> i already removed the staff lines in a music sheet. the problem is, a part of a hollow note was also removed causing me to have problems in getting the blobs. how can i restore the note?
----------------------------------------------------------------------------------------
Use the convex hull. Find it (with regionprops), then burn it into
the image to seal off the open portion.

Subject: how to blacken the center of a whole note?

From: ImageAnalyst

Date: 5 Sep, 2010 14:39:36

Message: 9 of 13

I think you probably don't know how to do that so, before you ask, I
thought I'd post a demo. You can find the convex hull with convhull
or regionprops. Then you'll need to draw lines and fill them in with
imfill. From one of my demos, here's how to burn the lines into the
binary image and the original gray image:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
%----- Burn line into image -----
monochromeImage = imread('pout.tif');
subplot(2, 2, 1);
imshow(monochromeImage);
title('Original Image', 'FontSize', fontSize);
% Create line mask, h, as an ROI object over the second image in the
bottom row.
subplot(2, 2, 2);
imshow(monochromeImage);
hLine = imline(gca,[10 100],[10 100]); % Second argument defines line
endpoints.
title('Original Image with line drawn over it', 'FontSize', fontSize);
% Create a binary image ("mask") from the ROI object.
binaryImage2 = hLine.createMask();
% Display the line mask.
subplot(2, 2, 3);
imshow(binaryImage2);
title('Binary mask of the line', 'FontSize', fontSize);
% Burn line into image by setting it to 255 wherever the mask is true.
burnedImage = monochromeImage; % Make a copy of the original first.
burnedImage(binaryImage2) = 255;
% Display the image with the "burned in" line.
subplot(2, 2, 4);
imshow(burnedImage);
title('New image with line burned into image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

Subject: how to blacken the center of a whole note?

From: Angelo

Date: 5 Sep, 2010 15:56:03

Message: 10 of 13

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a2ca4655-5c25-4c77-ab15-6d1443b04d44@i31g2000yqm.googlegroups.com>...
> I think you probably don't know how to do that so, before you ask, I
> thought I'd post a demo. You can find the convex hull with convhull
> or regionprops. Then you'll need to draw lines and fill them in with
> imfill. From one of my demos, here's how to burn the lines into the
> binary image and the original gray image:
>
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 20;
>
> % Change the current folder to the folder of this m-file.
> % (The line of code below is from Brett Shoelson of The Mathworks.)
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
> %----- Burn line into image -----
> monochromeImage = imread('pout.tif');
> subplot(2, 2, 1);
> imshow(monochromeImage);
> title('Original Image', 'FontSize', fontSize);
> % Create line mask, h, as an ROI object over the second image in the
> bottom row.
> subplot(2, 2, 2);
> imshow(monochromeImage);
> hLine = imline(gca,[10 100],[10 100]); % Second argument defines line
> endpoints.
> title('Original Image with line drawn over it', 'FontSize', fontSize);
> % Create a binary image ("mask") from the ROI object.
> binaryImage2 = hLine.createMask();
> % Display the line mask.
> subplot(2, 2, 3);
> imshow(binaryImage2);
> title('Binary mask of the line', 'FontSize', fontSize);
> % Burn line into image by setting it to 255 wherever the mask is true.
> burnedImage = monochromeImage; % Make a copy of the original first.
> burnedImage(binaryImage2) = 255;
> % Display the image with the "burned in" line.
> subplot(2, 2, 4);
> imshow(burnedImage);
> title('New image with line burned into image', 'FontSize', fontSize);
> set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
> screen.
> set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
>

here's an image when i removed the staff lines

http://i54.tinypic.com/34ysdts.jpg

so i have to connect the gap of the half note with a line? won't it be possible if i connect it with an arc so i can restore the note?

Subject: how to blacken the center of a whole note?

From: ImageAnalyst

Date: 5 Sep, 2010 16:16:23

Message: 11 of 13

Yes, but first you'll have to identify the two blobs that need to be
connected, and that's not easy. There are lots and lots of blobs in
the image, so you'll need several rules to determine which two should
be connected, for example if the distance between endpoints or
centroids is less than some distance, and other rules like that.
Maybe first get rid of the vertical lines, then if two blobs are of a
certain size and within a certain distance, connect them, or something
like that. I can't really do much development for you, since to make
it robust might take several days of programming. But presumably
you've got the rest of the semester to work on it. Good luck.

Subject: how to blacken the center of a whole note?

From: Angelo

Date: 6 Sep, 2010 00:03:06

Message: 12 of 13

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5ad955b0-2b1f-4deb-85b6-771b542d084f@t20g2000yqa.googlegroups.com>...
> Yes, but first you'll have to identify the two blobs that need to be
> connected, and that's not easy. There are lots and lots of blobs in
> the image, so you'll need several rules to determine which two should
> be connected, for example if the distance between endpoints or
> centroids is less than some distance, and other rules like that.
> Maybe first get rid of the vertical lines, then if two blobs are of a
> certain size and within a certain distance, connect them, or something
> like that. I can't really do much development for you, since to make
> it robust might take several days of programming. But presumably
> you've got the rest of the semester to work on it. Good luck.

do you have any suggestions on how can i remove the vertical lines on that image?

Subject: how to blacken the center of a whole note?

From: ImageAnalyst

Date: 6 Sep, 2010 01:06:00

Message: 13 of 13

try a 1-D median filter:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Documents and Settings\tk2013\My Documents\Temporary
stuff';
baseFileName = 'notes.jpg';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
    grayImage = rgb2gray(grayImage);
end
% Display the original gray scale image.
subplot(2, 1, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

% Median filter it.
medianFilteredImage = medfilt2(grayImage, [1 5]);
subplot(2, 1, 2);
imshow(medianFilteredImage, []);
title('Median Filtered Image - no lines', 'FontSize', fontSize);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us