Canny Edge Detection

Determine Coordinates of Edges

Assuming the image is sized XxY pixels. Then you can resize an image into a 1xY column and a Xx1 row of pixels, where each pixel's color value is the average of the respective pixels of all pixels which were in the same row or same column as the respective column/row pixel.

As an example which can be seen below, I'll first resize the new canny-edges.png to 4xY and Xx4 images:

canny-4cols.png

canny-4rows.png

Now that the previous images visualized what the compression-resizing of an image into a few columns or rows of pixels will achieve, let's do it with a single column and a single row. At the same time we'll change the output format to text, not PNG, in order to get the coordinates of these pixels which are white:

As you can see, the detected edges from the text also influenced the grayscale values of the pixels. So we could introduce an additional -threshold 50% operation into our commands, to get pure black+white output:

I'll not quote the contents of the new text files here, you can try it and look for yourself if you are interested. Instead, I'll do a shortcut: I'll output the textual representation of the pixel color values to <stdout> and directly grep it for all non-black pixels:

More options to explore

autotrace

You can streamline the above procedure (even transform it into an automatically working script if you want) even more, by converting the intermediate "canny-edges.png" into an SVG vector graphic, for example by running it through autotrace...

This could be useful if your sticky note is tilted or rotated.

Hough Line Detection

Once you have the "canny" lines, you could also apply the Hough Line Detection algorithm on them:

Note that the -hough-lines operator extends and draws detected lines from one edge (with floating point values) to another edge of the original image.

While the previous command finally converted the lines to a PNG the -hough-lines operator really generates an MVG file (Magick Vector Graphics) internally. That means you could actually read the source code of the MVG file, and determine the mathematical parameters of each line which is depicted in the "red lines" image:

convert \
canny-edges.png \
-hough-lines 5x5+20 \
lines.mvg

This is more sophisticated and also works for edges which are not strictly horizontal and/or vertical.

But your example image does use horizontal and vertical edges, so you can even use simple shell commands to discover these.

There are 80 line descriptions in total in the generated MVG file. You can identify all horizontal lines in that file: