# Decoding Music in Staff Notation using ImageIdentify

I wrote this Code fragment

Which is a E (quarter) note in Treble Clef. Instead Mathematica simply classified it as a "musical note" Can we do better?

• I’m sure one could, with some effort. I wanted to point out this though: you have to your credit 19 questions that have received answers, some heavily upvoted, and yet you accepted only 4 of those. Accepting valuable answers that solve your problem in due time is good form on this forum. Consider doing some of that. Apr 25, 2020 at 16:29
• Sorry, I will do that now. Been lazy I guess. But here is a blanket upvote to all those who took the time to answer my questions.. Apr 25, 2020 at 16:55
• There are four musical clefs that come in various key indications; none of which are indicated in the image. With out this information all anyone (including ImageIdentify) can do is identify it as a musical note. I look at it in the context of a bass clef and see either a low G, G-sharp, or G-flat. Jun 4, 2020 at 12:13
• Assume some such qualifier is provided. Assume its all Treble clef.. Jun 5, 2020 at 15:25

Here is my humble approach.

sheet = Import["https://rmurta.s3-sa-east-1.amazonaws.com/mathematica-playground/sheet.png"];
note = Import["https://rmurta.s3-sa-east-1.amazonaws.com/mathematica-playground/note.png"];

examples = Map[ImageResize[#, 100]&]/@ <|
"mi" -> (ImageCompose[sheet, note,{200,235} + #]&/@RandomReal[{-5,5},{4,2}]),
"fa" -> (ImageCompose[sheet, note,{200,280} + #]&/@RandomReal[{-5,5},{4,2}]),
"sol" ->(ImageCompose[sheet, note,{200,360} + #]&/@RandomReal[{-5,5},{4,2}]),
"la" ->(ImageCompose[sheet, note,{200,400} + #]&/@RandomReal[{-5,5},{4,2}]),
"si" ->(ImageCompose[sheet, note,{200,430} + #]&/@RandomReal[{-5,5},{4,2}]),
"do" ->(ImageCompose[sheet, note,{200,490} + #]&/@RandomReal[{-5,5},{4,2}])
|>;

c = Classify[examples];

Copying your example into Mathematica, and applying c into It:

• Thanks but did not work for any other notes.. May 5, 2020 at 7:32
• Can you please send me the images of list of notes you have that worked for you.. May 5, 2020 at 14:56
• Just execute: ImageCompose[sheet, note,{200,360}] May 5, 2020 at 15:38
• I thought as much. This is unrelated to Machine Learning. For example, it does not work for handwritten notes. I wanted a machine-learning algorithm that can identify notes the way a human would. May 6, 2020 at 8:30
• I want to use commands like ImageIdentify that are machine learning related. May 6, 2020 at 8:31