[CentralOH] Python library for image processing?

Eric Miller miller.eric.t at gmail.com
Thu Apr 11 12:58:07 EDT 2019


So...I posted this problem to both SO and several subreddits....and got
almost no response!  That tells me that either the question is *really*
hard, or I'm asking it the wrong way (or both!).  Anyway, Eric and others I
think I have landed on an approach that might work.  Take a look and let me
know if this is sane?

- each map image only has a small number of colors (between 3 and 20
depending on the map).  We'll call the number of colors in a given image *n*
- convert the image to an RGB numpy array
- create *n* number of secondary arrays from that array, each with only one
color represented.  Each will be a 2D np array of x/y coordinates, 'e.g.
the *list* of all x/y coordinates of a given color' (see [1] below for an
example of what this list will look like)
- for each pixel, and for each of the 2d arrays, use scipy.spatial.KDTree [1]
to determine the closet pixel for each color.  Progressively pop this value
into a new 3d array.  that's original x and y dims, plus a new 3rd dim
that's a tuple of length *n*, containing the the closest distances to all
colors for that pixel, indexed 0-n *(or should this be n number of new
dimensions instead of a tuple??)*
- do some yet-to-be determined numpy voodoo SQL like query to determine the
pixels whose greatest distance to all other colors (call that *r*)  is less
than all the other pixels in the array.
- the rest is just drawing circles with those pixels at the center, with
radius *r*

[1] https://stackoverflow.com/a/32781737/1404135

On Wed, Apr 10, 2019 at 4:58 PM Eric Miller <miller.eric.t at gmail.com> wrote:

> Thanks E.  Your suggestion got me on the right track, was able to create a
> numpy array from an image.  I have some questions about where to go from
> there...mostly about handrolling my own cart coordinate code to brute force
> pixel by pixel, vs. 'some lib/method that already solves this, that I think
> exists but don't know'
>
> Rather than spam this list, I created an SO question.  Happy and
> appreciative if anyone can take a look...
>
>
> https://stackoverflow.com/questions/55621100/find-closest-clusters-of-colors-in-a-numpy-array-from-an-image-file
>
> On Tue, Apr 9, 2019 at 5:22 PM Eric Floehr <eric at intellovations.com>
> wrote:
>
>> Eric,
>>
>> Awesome, that sounds like a really fun project! Would love to watch your
>> progress on that! I bought KSP all the way back in 2013 but haven't played
>> recently. It looks like they have added a bunch of cool stuff!
>>
>> Cheers,
>> Eric
>>
>>
>> On Tue, Apr 9, 2019 at 5:05 PM Eric Miller <miller.eric.t at gmail.com>
>> wrote:
>>
>>> thanks Eric   I do indeed plan on doing an operation on every pixel in
>>> the image.  Sounds like I may need to use a few libs to achieve it
>>> efficiently.
>>>
>>> The goal is to parse Kerbal Space Program biome map images
>>> <https://wiki.kerbalspaceprogram.com/wiki/Biome>, to determine the
>>> landing spots that are nearest to the most number of surface biomes.
>>>
>>> On Tue, Apr 9, 2019 at 4:17 PM Eric Floehr <eric at intellovations.com>
>>> wrote:
>>>
>>>> Eric,
>>>>
>>>> Depending on what you want to do, getPixel may or may not be too slow
>>>> for you. Both scipy[1] and skimage (sci-kit image)[2] manipulate images as
>>>> numpy arrays which allow you to do very efficient matrix operations, if
>>>> say, you are doing an operation on every pixel in an image.
>>>>
>>>> You can also easily load an image as a numpy array directly:
>>>>
>>>> from PIL import Image
>>>> import numpy as np
>>>> image = Image.open('xyz.png')
>>>> img_array = np.array(image)
>>>>
>>>> [1] http://cs231n.github.io/python-numpy-tutorial/#scipy-image
>>>>
>>>> [2] https://scikit-image.org/
>>>>
>>>>
>>>> On Tue, Apr 9, 2019 at 4:04 PM Eric Miller <miller.eric.t at gmail.com>
>>>> wrote:
>>>>
>>>>> Thanks, that look perfect.
>>>>>
>>>>> On Tue, Apr 9, 2019, 3:57 PM Joe Shaw <joe at joeshaw.org> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Check out Pillow, https://pillow.readthedocs.io/en/stable/.  It is a
>>>>>> fork of the earlier PIL library.  It also integrates nicely with numpy if
>>>>>> you need it.
>>>>>>
>>>>>> If you needed something more powerful, like bindings to the
>>>>>> ImageMagick C library, then something like Wand might be better.
>>>>>> https://github.com/emcconville/wand
>>>>>>
>>>>>> Joe
>>>>>>
>>>>>> On Tue, Apr 9, 2019 at 3:48 PM Eric Miller <miller.eric.t at gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Looking for a library to parse each pixel in an image file. Need to
>>>>>>> map each x,y pixel to its associated RGB values.
>>>>>>>
>>>>>>> Any recommendations for a lib that will do this well?
>>>>>>>
>>>>>>> Thanks!
>>>>>>> _______________________________________________
>>>>>>> CentralOH mailing list
>>>>>>> CentralOH at python.org
>>>>>>> https://mail.python.org/mailman/listinfo/centraloh
>>>>>>>
>>>>>> _______________________________________________
>>>>>> CentralOH mailing list
>>>>>> CentralOH at python.org
>>>>>> https://mail.python.org/mailman/listinfo/centraloh
>>>>>>
>>>>> _______________________________________________
>>>>> CentralOH mailing list
>>>>> CentralOH at python.org
>>>>> https://mail.python.org/mailman/listinfo/centraloh
>>>>>
>>>> _______________________________________________
>>>> CentralOH mailing list
>>>> CentralOH at python.org
>>>> https://mail.python.org/mailman/listinfo/centraloh
>>>>
>>> _______________________________________________
>>> CentralOH mailing list
>>> CentralOH at python.org
>>> https://mail.python.org/mailman/listinfo/centraloh
>>>
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> https://mail.python.org/mailman/listinfo/centraloh
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20190411/d8b01b71/attachment.html>


More information about the CentralOH mailing list