0

Could anyone let me know of any library/function in preferably MATLAB/Python/Java which takes a black&white picture with a curve and returns two arrays describing the x and y components?

My initial idea was to take such a picture map it to its logical matrix and take the positions from there. The drawback is that I would work with integer values only and rescaling to floating point numbers would be merely impossible.

An example of such picture is

enter image description here

ZdaR
  • 22,343
  • 7
  • 66
  • 87
Marius
  • 139
  • 4
  • Can you use numpy library ? – ZdaR Feb 08 '17 at 12:29
  • It's a bit unclear to me what you mean by "two arrays describing the x and y components". The coordinates of all black pixels? But what of the grey pixels? If I understand you correctly, you want a a representation of the actual path used to draw the picture? Maybe you should try to vectorize the bitmap, for example using inkscape. – Fritz Feb 08 '17 at 12:34
  • You can certainly do that in python with pillow and numpy. – Jannick Feb 08 '17 at 12:46
  • Maybe this answer with MATLAB brings you some inspiration: http://stackoverflow.com/a/41991740/3382783 – Iban Cereijo Feb 08 '17 at 13:17

1 Answers1

0

I know this is crude, but it seems to work.

from PIL import Image
#
print "\nStarting script"
#
# Load the image
im = Image.open('Pixels_Test_Image.png')
px = im.load()
#
# Determine the image size
width, height = im.size
print "width, height = " + str(width) + ", " + str(height)
#
# Loop over each pixel and test rgb values to find black pixels
non_white_i_pixel = []
non_white_j_pixel = []
i_pixel = 0
set_limit = 100
while i_pixel < width:
    j_pixel = 0
    while j_pixel < height:
        r, g, b, xx = (px[i_pixel, j_pixel])
        #print i_pixel, j_pixel, a, b, c, d
        if(r < set_limit and g < set_limit and b < set_limit):
            non_white_i_pixel.append(i_pixel)
            non_white_j_pixel.append(j_pixel)
        j_pixel += 1
    i_pixel += 1
#
print "len(non_white_i_pixel) = " + str(len(non_white_i_pixel))
print "len(non_white_j_pixel) = " + str(len(non_white_j_pixel))
print non_white_i_pixel
print non_white_j_pixel
#
print "\nFinished script"
R. Wayne
  • 417
  • 1
  • 9
  • 17