rimagecoordinatesmonochrome

Convert monochrom image into x,y coordinates into a dataframe


I want to turn the "black values" of a monochrom image into x-y points to plot them in a scatter plot later.

The following image in the link explains easily what im looking for.

enter image description here

I also want to control the amount of "points per area"!

Lets take:


(source: tieudesigns.com)

as our example image.

Edit:

here is what i came up with:

> library("magick")
> test <- image_read('*CENSORED*\\white-circle-black-background.jpg')
> testDS <- as.raster(test)

Solution

  • Just demonstrating what I was alluding to in the comments. You would have to adapt the approach to R as I am showing a technique using ImageMagick at the command line:

    convert mask.jpg -threshold 50% -colorspace gray -fx "(1-u)*rand()>0.8 ? 0:1" result.png
    

    enter image description here

    Or changing the threshold:

    convert mask.jpg -threshold 50% -colorspace gray -fx "(1-u)*rand()>0.9 ? 0:1" result.png
    

    enter image description here

    The interesting part is obviously the -fx expression, which uses the value of each pixel - referred to as u - and scaled on the range [0,1] where 0 is black and 1 is white. Basically I invert the pixel (1-u) and multiply by a random number then threshold it. Changing the threshold changes the density of pixels. Depending on the result, I either output a black or a white pixel.

    I am not sure what you mean by "translate those values into coordinates", but if you really want a list of the black pixel coordinates:

    convert mask.jpg -threshold 50% -colorspace gray -fx "(1-u)*rand()>0.8?0:1" -depth 8 txt: | grep "(0)"
    

    Sample Output

    2,0: (0)  #000000  gray(0)
    4,0: (0)  #000000  gray(0)
    6,0: (0)  #000000  gray(0)
    7,0: (0)  #000000  gray(0)
    8,0: (0)  #000000  gray(0)
    10,0: (0)  #000000  gray(0)
    13,0: (0)  #000000  gray(0)
    14,0: (0)  #000000  gray(0)