a-pandas-ex-image-tools


Namea-pandas-ex-image-tools JSON
Version 0.11 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/a_pandas_ex_image_tools
SummaryUses pandas/numpy/numexpr for operations on pictures - very fast
upload_time2023-09-05 21:20:08
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords pandas opencv cv2 images pixels detection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
```python
$pip install a-pandas-ex-image-tools
import cv2
import pandas as pd

from a_cv2_imshow_thread import add_imshow_thread_to_cv2
add_imshow_thread_to_cv2()

from a_pandas_ex_image_tools import pd_add_image_tools, debugger, get_list_of_all_colors_in_range

pd_add_image_tools()
#you can ignore all exceptions
debugger.stop_on_exceptions = True

#Useful if you want to ignore every exception, but want to see what's going on
debugger.print_all_exceptions = True

pythonlogo = 'https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png'


```


<img src="https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png"/>



```python
df = pd.Q_image2df(pythonlogo)
df
Out[5]: 
         x    y  red  green  blue
0        0    0    0      0     0
1        1    0    0      0     0
2        2    0    0      0     0
3        3    0    0      0     0
4        4    0    0      0     0
    ...  ...  ...    ...   ...
39995  195  199    0      0     0
39996  196  199    0      0     0
39997  197  199    0      0     0
39998  198  199    0      0     0
39999  199  199    0      0     0
[40000 rows x 5 columns]
```



```python
df1 = df.im_multicolor_lookup([(255, 232, 115)])
df1
Out[11]: 
         x    y  red  green  blue
13337  137   66  255    232   115
13338  138   66  255    232   115
13339  139   66  255    232   115
13340  140   66  255    232   115
13341  141   66  255    232   115
    ...  ...  ...    ...   ...
25269   69  126  255    232   115
25270   70  126  255    232   115
25467   67  127  255    232   115
25468   68  127  255    232   115
25667   67  128  255    232   115
[608 rows x 5 columns]
```



```python
df1.im_xy_to_convex_hull()  # get the convex hull 
Out[12]: 
array([[[154,  67]],
       [[153,  68]],
       [[ 73, 124]],
       [[ 67, 128]],
       [[ 67, 114]],
       [[ 70, 108]],
       [[ 74, 104]],
       [[137,  66]],
       [[150,  66]]], dtype=int32)
```



```python
df.im_show_df_image()  # cv2.imshow
```



```python
# converts the pandas DataFrame back to a numpy array
df.im_df_to_np_image()  
```



```python
df.im_print_all_colors()  # prints all colors sorted by qty
```



```python
df1.im_xy_to_shapely()
Out[13]: <shapely.geometry.polygon.Polygon at 0x21302f70>
```



```python
# Gets all x,y coordinates as a numpy array
df1.im_xy_to_np()
Out[14]: 
array([[137,  66],
       [138,  66],
       [139,  66],
       ...,
       [ 67, 127],
       [ 68, 127],
       [ 67, 128]], dtype=uint16)
```



```python
# you can even edit images 
df.loc[df.im_multicolor_lookup([(0,0,0)]).index, ['red', 'green', 'blue']] = [255,255,0] 
```



<img src="https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2003_40_27-.png"/>






```python
# Replace a color range with one color
df.loc[df.im_multicolor_lookup(get_list_of_all_colors_in_range((0,0,0), (10,10,10))).index, ['red', 'green', 'blue']] = [255,255,0] 
```



```python
# cluster colors in areas
# More about the parameters: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html
multilookupdf = df.im_multicolor_lookup(
    colorlist=[(255, 232, 115), (255, 0, 0), (48, 105, 152)], ).im_xy_to_color_clusters(eps=2, min_samples=4, n_jobs=-1,
    poly_color=(255, 255, 0), poly_outline_thickness=3, rectanglecolor=(0, 255, 0), )
multilookupdf
Out[24]: 
  aa_repr_point             aa_bounds  ... aa_draw_poly aa_draw_rectangle
0     (124, 82)    (106, 66, 132, 96)  ...           ()                ()
1     (142, 71)    (137, 66, 154, 79)  ...           ()                ()
2     (73, 119)   (67, 102, 104, 128)  ...           ()                ()
3    (158, 123)  (144, 117, 164, 131)  ...           ()                ()
4    (119, 155)   (93, 139, 132, 167)  ...           ()                ()
[5 rows x 9 columns]
```



```python
# Cluster multiple colors
multilookupdf = df.im_multicolor_lookup(
    colorlist=[(255, 232, 115), (255, 0, 0), (48, 105, 152)], ).im_xy_to_color_clusters(eps=2, min_samples=4, n_jobs=-1,
    poly_color=(255, 0, 120), poly_outline_thickness=3, rectanglecolor=(0, 255, 0), )
```



```python
# show the clustered results
npimage = df.im_df_to_np_image().copy()
multilookupdf.aa_draw_rectangle.apply(lambda x: x(npimage))
multilookupdf.aa_draw_poly.apply(lambda x: x(npimage))
cv2.imshow_thread(npimage)
```



<img src="https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2003_49_27-.png"/>





```python
bab=df.im_multicolor_lookup(colorlist=[(255, 232, 115), (48, 105, 152)], ).im_xy_to_merged_color_clusters(
    image=df.im_df_to_np_image().copy(), show_results=True, max_merge_distance=2, eps=2, min_samples=4, n_jobs=-1,
    poly_color=(255, 255, 0), poly_outline_thickness=3, rectanglecolor=(0, 255, 0), mergedcolor=(0, 0, 255), )


bab
Out[6]: 
  aa_repr_point  ...                                             bb_pic
0     (124, 82)  ...  [[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], ...
1     (142, 71)  ...  [[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], ...
2     (73, 119)  ...  [[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], ...
```



<img src="https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2004_02_09-.png"/>





<img src="https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2004_01_57-.png"/>




```python
# Do you prefer working with dicts instead of DataFrames? 
df.im_get_color_lookup_dict()
{(0,
  0,
  0): array([[  0,   0],
        [  1,   0],
        [  2,   0],
        ...,
        [196, 199],
        [197, 199],
        [198, 199]], dtype=uint16),
 (15, 33, 48): array([[199, 199]], dtype=uint16),
 (17, 35, 49): array([[131,  88]], dtype=uint16),
 (17, 35, 50): array([[ 63, 114]], dtype=uint16),
 (17, 36, 53): array([[75, 99]], dtype=uint16),
 (17,
  37,
  53): array([[119,  97],
        [129,  91]], dtype=uint16),
 (18, 36, 50): array([[126,  94]], dtype=uint16),
 (18, 37, 52): array([[125,  35]], dtype=uint16),
 (19, 38, 53): array([[ 68, 104]], dtype=uint16),
 (19,
  39,
  55): array([[ 36, 124],
        [ 73, 100]], dtype=uint16),
...
```



```python
df.im_get_image_size()
# Out[7]: [(0, 0, 200, 200)]
```



```python
# Count colors in certain regions
df.im_get_colors_in_regions_and_count(regions=[(10, 10, 100, 100), (150, 150, 160, 170)])
Out[11]: 
     red  green  blue  ...  size_of_area  percentage_of_area                region
0      0      0     0  ...          8100           61.925926    (10, 10, 100, 100)
1     69    132   182  ...          8100            1.790123    (10, 10, 100, 100)
2    255    255   255  ...          8100            1.160494    (10, 10, 100, 100)
3     67    129   179  ...          8100            1.148148    (10, 10, 100, 100)
4     62    123   172  ...          8100            1.135802    (10, 10, 100, 100)
..   ...    ...   ...  ...           ...                 ...                   ...
218   59    110   151  ...          8100            0.012346    (10, 10, 100, 100)
219   59    111   153  ...          8100            0.012346    (10, 10, 100, 100)
220   60    112   154  ...          8100            0.012346    (10, 10, 100, 100)
221   62    111   147  ...          8100            0.012346    (10, 10, 100, 100)
222    0      0     0  ...           200          115.500000  (150, 150, 160, 170)
[223 rows x 7 columns]
```



```python
# You can limit the search region
df.im_limit_search_areas(areas=[(0, 0, 50, 50), (50, 50, 150, 170)]).im_multicolor_lookup(
    colorlist=[(255, 232, 115), (255, 0, 0), (48, 105, 152)])
Out[12]: 
         x    y  red  green  blue
13332  132   66   48    105   152
13337  137   66  255    232   115
13338  138   66  255    232   115
13339  139   66  255    232   115
13340  140   66  255    232   115
    ...  ...  ...    ...   ...
33502  102  167  255      0     0
33503  103  167  255      0     0
33504  104  167  255      0     0
33505  105  167  255      0     0
33506  106  167  255      0     0
[1352 rows x 5 columns]
```



```python
# define regions for every individual color
colordict = {(255, 0, 0): [(0, 0, 50, 50), (0, 0, 1000, 1000)],
    (255, 232, 115): [(0, 0, 1000, 1000), (500, 500, 502, 502), (900, 900, 1000, 950), ],
    (255, 255, 255): [(0, 0, 1000, 1000), (400, 200, 800, 400)], (0, 176, 111): [(0, 0, 1000, 1000)],
    (57, 59, 61): [(0, 0, 1000, 1000)], (0, 0, 0): [(0, 0, 1000, 1000)], }
regi = df.im_get_coords_of_colors_in_regions(colordict)

         x    y  red  green  blue
0        0    0    0      0     0
1        1    0    0      0     0
2        2    0    0      0     0
3        3    0    0      0     0
4        4    0    0      0     0
    ...  ...  ...    ...   ...
39995  195  199    0      0     0
39996  196  199    0      0     0
39997  197  199    0      0     0
39998  198  199    0      0     0
39999  199  199    0      0     0
[28789 rows x 5 columns]
```



```python
# You can use a multi index to check individual pixels 
dfxy = df.im_xy_as_index()

         red  green  blue
x   y                    
0   0      0      0     0
    1      0      0     0
    2      0      0     0
    3      0      0     0
    4      0      0     0
      ...    ...   ...
199 195    0      0     0
    196    0      0     0
    197    0      0     0
    198    0      0     0
    199    0      0     0
[40000 rows x 3 columns]

# Let's get the RGB values using the DataFrame we have just created
dfxy.loc[[(0,100), (100,100), (44,40)]]

Out[17]: 
         red  green  blue
x   y                    
0   100    0      0     0
100 100    0      0     0
44  40     0      0     0
```



```python
# can also be done like that:
coordlist = [(10, 10), (100, 100), (50, 80)]
colors_of_coords = df.im_get_colors_of_coords(coordlist)
colors_of_coords
Out[19]: 
         red  green  blue
x   y                    
10  10     0      0     0
100 100    0      0     0
50  80    70    134   184
```



```python
Compare 2 images:
pythonlogo = 'https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png'
df = pd.Q_image2df(pythonlogo)
df.loc[df.im_multicolor_lookup(get_list_of_all_colors_in_range((0,0,0), (10,10,10))).index, ['red', 'green', 'blue']] = [255,255,0] 
pythonlogo = 'https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png'
df2 = pd.Q_image2df(pythonlogo)
df2.im_compare_2_images(df)
Out[23]: 
       pic_index    x    y  r1  g1  b1   r2   g2  b2
0              0    0    0   0   0   0  255  255   0
1              1    1    0   0   0   0  255  255   0
2              2    2    0   0   0   0  255  255   0
3              3    3    0   0   0   0  255  255   0
4              4    4    0   0   0   0  255  255   0
          ...  ...  ...  ..  ..  ..  ...  ...  ..
27510      39995  195  199   0   0   0  255  255   0
27511      39996  196  199   0   0   0  255  255   0
27512      39997  197  199   0   0   0  255  255   0
27513      39998  198  199   0   0   0  255  255   0
27514      39999  199  199   0   0   0  255  255   0
[27515 rows x 9 columns]
```


```python
# If you want to do additional stuff with OpenCV:
df.im_xy_to_cv2_coords()
Out[28]: 
array([[[  0,   0],
        [  1,   0],
        [  2,   0],
        ...,
        [197, 199],
        [198, 199],
        [199, 199]]])
```



```python
df.im_singlecolor_lookup((255,255,0))
Out[45]: 
         x    y  red  green  blue
0        0    0  255    255     0
1        1    0  255    255     0
2        2    0  255    255     0
3        3    0  255    255     0
4        4    0  255    255     0
    ...  ...  ...    ...   ...
39995  195  199  255    255     0
39996  196  199  255    255     0
39997  197  199  255    255     0
39998  198  199  255    255     0
39999  199  199  255    255     0
[27515 rows x 5 columns]
```



```python
df.im_get_closest_colors([(10,3,4)])
Out[55]: 
       r    g    b      rating         rgb
0      0    0    0   11.179688  (10, 3, 4)
1     15   33   48   53.500000  (10, 3, 4)
2     17   35   49   55.656250  (10, 3, 4)
3     17   35   50   56.468750  (10, 3, 4)
4     18   36   50   57.187500  (10, 3, 4)
..   ...  ...  ...         ...         ...
712  250  242  218  400.750000  (10, 3, 4)
713  252  247  230  411.250000  (10, 3, 4)
714  241  244  246  412.250000  (10, 3, 4)
715  253  251  243  421.500000  (10, 3, 4)
716  255  255  255  432.000000  (10, 3, 4)
[717 rows x 5 columns]
```



```python
get_list_of_all_colors_in_range((0,0,0), (3,4,3))

Out[59]: 
[(0, 0, 0),
 (0, 0, 1),
 (0, 0, 2),
 (0, 0, 3),
 (0, 1, 0),
 (0, 1, 1),
 (0, 1, 2),
 (0, 1, 3),
 (0, 2, 0),
 (0, 2, 1),
 (0, 2, 2),
 (0, 2, 3),
 (0, 3, 0),
```




```python
dfr = df.im_rgb_as_index()
Out[65]: 
                  x    y
red green blue          
0   0     0       0    0
          0       1    0
          0       2    0
          0       3    0
          0       4    0
             ...  ...
255 255   255   120  155
          255   121  155
          255   117  156
          255   118  156
          255   119  156
[40000 rows x 2 columns]


#Now you can use dfr.loc to get the coordinates
dfr.loc[(17,37,53)]
dfr.loc[ (39,83,119)]
```



```python
# finds all colors that only exist in the region and nowhere else in the picture 
df.im_get_unique_colors_in_region([(0,0,100,100)])
Out[72]: 
        x   y  red  green  blue
18432  32  92   73    137   188
18433  33  92   73    137   187
18434  34  92   72    136   187
18435  35  92   72    136   186
18436  36  92   72    135   186
    ..  ..  ...    ...   ...
14255  55  71   71    135   186
14256  56  71   71    135   185
14257  57  71   71    134   185
12266  66  61   53    102   140
18431  31  92   59    111   153
[845 rows x 5 columns]
```

```python
# finds all colors that are in the region and somewhere else in the picture 
df.im_get_not_unique_colors_in_region([(0,0,100,100)])
Out[73]: 
         x    y  red  green  blue
0        0    0    0      0     0
1        1    0    0      0     0
2        2    0    0      0     0
3        3    0    0      0     0
4        4    0    0      0     0
    ...  ...  ...    ...   ...
20096   96  100    0      0     0
20097   97  100    0      0     0
20098   98  100    0      0     0
20099   99  100    0      0     0
20100  100  100    0      0     0
[9356 rows x 5 columns]
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/a_pandas_ex_image_tools",
    "name": "a-pandas-ex-image-tools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pandas,OpenCV,cv2,images,pixels,detection",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/8f/0ee1800d9ebb4f2e883faa7aff7460bf8e57f53e71b38e17fcb4e9b6b8ba/a_pandas_ex_image_tools-0.11.tar.gz",
    "platform": null,
    "description": "\r\n```python\r\n$pip install a-pandas-ex-image-tools\r\nimport cv2\r\nimport pandas as pd\r\n\r\nfrom a_cv2_imshow_thread import add_imshow_thread_to_cv2\r\nadd_imshow_thread_to_cv2()\r\n\r\nfrom a_pandas_ex_image_tools import pd_add_image_tools, debugger, get_list_of_all_colors_in_range\r\n\r\npd_add_image_tools()\r\n#you can ignore all exceptions\r\ndebugger.stop_on_exceptions = True\r\n\r\n#Useful if you want to ignore every exception, but want to see what's going on\r\ndebugger.print_all_exceptions = True\r\n\r\npythonlogo = 'https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png'\r\n\r\n\r\n```\r\n\r\n\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png\"/>\r\n\r\n\r\n\r\n```python\r\ndf = pd.Q_image2df(pythonlogo)\r\ndf\r\nOut[5]: \r\n         x    y  red  green  blue\r\n0        0    0    0      0     0\r\n1        1    0    0      0     0\r\n2        2    0    0      0     0\r\n3        3    0    0      0     0\r\n4        4    0    0      0     0\r\n    ...  ...  ...    ...   ...\r\n39995  195  199    0      0     0\r\n39996  196  199    0      0     0\r\n39997  197  199    0      0     0\r\n39998  198  199    0      0     0\r\n39999  199  199    0      0     0\r\n[40000 rows x 5 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\ndf1 = df.im_multicolor_lookup([(255, 232, 115)])\r\ndf1\r\nOut[11]: \r\n         x    y  red  green  blue\r\n13337  137   66  255    232   115\r\n13338  138   66  255    232   115\r\n13339  139   66  255    232   115\r\n13340  140   66  255    232   115\r\n13341  141   66  255    232   115\r\n    ...  ...  ...    ...   ...\r\n25269   69  126  255    232   115\r\n25270   70  126  255    232   115\r\n25467   67  127  255    232   115\r\n25468   68  127  255    232   115\r\n25667   67  128  255    232   115\r\n[608 rows x 5 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\ndf1.im_xy_to_convex_hull()  # get the convex hull \r\nOut[12]: \r\narray([[[154,  67]],\r\n       [[153,  68]],\r\n       [[ 73, 124]],\r\n       [[ 67, 128]],\r\n       [[ 67, 114]],\r\n       [[ 70, 108]],\r\n       [[ 74, 104]],\r\n       [[137,  66]],\r\n       [[150,  66]]], dtype=int32)\r\n```\r\n\r\n\r\n\r\n```python\r\ndf.im_show_df_image()  # cv2.imshow\r\n```\r\n\r\n\r\n\r\n```python\r\n# converts the pandas DataFrame back to a numpy array\r\ndf.im_df_to_np_image()  \r\n```\r\n\r\n\r\n\r\n```python\r\ndf.im_print_all_colors()  # prints all colors sorted by qty\r\n```\r\n\r\n\r\n\r\n```python\r\ndf1.im_xy_to_shapely()\r\nOut[13]: <shapely.geometry.polygon.Polygon at 0x21302f70>\r\n```\r\n\r\n\r\n\r\n```python\r\n# Gets all x,y coordinates as a numpy array\r\ndf1.im_xy_to_np()\r\nOut[14]: \r\narray([[137,  66],\r\n       [138,  66],\r\n       [139,  66],\r\n       ...,\r\n       [ 67, 127],\r\n       [ 68, 127],\r\n       [ 67, 128]], dtype=uint16)\r\n```\r\n\r\n\r\n\r\n```python\r\n# you can even edit images \r\ndf.loc[df.im_multicolor_lookup([(0,0,0)]).index, ['red', 'green', 'blue']] = [255,255,0] \r\n```\r\n\r\n\r\n\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2003_40_27-.png\"/>\r\n\r\n\r\n\r\n\r\n\r\n\r\n```python\r\n# Replace a color range with one color\r\ndf.loc[df.im_multicolor_lookup(get_list_of_all_colors_in_range((0,0,0), (10,10,10))).index, ['red', 'green', 'blue']] = [255,255,0] \r\n```\r\n\r\n\r\n\r\n```python\r\n# cluster colors in areas\r\n# More about the parameters: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html\r\nmultilookupdf = df.im_multicolor_lookup(\r\n    colorlist=[(255, 232, 115), (255, 0, 0), (48, 105, 152)], ).im_xy_to_color_clusters(eps=2, min_samples=4, n_jobs=-1,\r\n    poly_color=(255, 255, 0), poly_outline_thickness=3, rectanglecolor=(0, 255, 0), )\r\nmultilookupdf\r\nOut[24]: \r\n  aa_repr_point             aa_bounds  ... aa_draw_poly aa_draw_rectangle\r\n0     (124, 82)    (106, 66, 132, 96)  ...           ()                ()\r\n1     (142, 71)    (137, 66, 154, 79)  ...           ()                ()\r\n2     (73, 119)   (67, 102, 104, 128)  ...           ()                ()\r\n3    (158, 123)  (144, 117, 164, 131)  ...           ()                ()\r\n4    (119, 155)   (93, 139, 132, 167)  ...           ()                ()\r\n[5 rows x 9 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\n# Cluster multiple colors\r\nmultilookupdf = df.im_multicolor_lookup(\r\n    colorlist=[(255, 232, 115), (255, 0, 0), (48, 105, 152)], ).im_xy_to_color_clusters(eps=2, min_samples=4, n_jobs=-1,\r\n    poly_color=(255, 0, 120), poly_outline_thickness=3, rectanglecolor=(0, 255, 0), )\r\n```\r\n\r\n\r\n\r\n```python\r\n# show the clustered results\r\nnpimage = df.im_df_to_np_image().copy()\r\nmultilookupdf.aa_draw_rectangle.apply(lambda x: x(npimage))\r\nmultilookupdf.aa_draw_poly.apply(lambda x: x(npimage))\r\ncv2.imshow_thread(npimage)\r\n```\r\n\r\n\r\n\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2003_49_27-.png\"/>\r\n\r\n\r\n\r\n\r\n\r\n```python\r\nbab=df.im_multicolor_lookup(colorlist=[(255, 232, 115), (48, 105, 152)], ).im_xy_to_merged_color_clusters(\r\n    image=df.im_df_to_np_image().copy(), show_results=True, max_merge_distance=2, eps=2, min_samples=4, n_jobs=-1,\r\n    poly_color=(255, 255, 0), poly_outline_thickness=3, rectanglecolor=(0, 255, 0), mergedcolor=(0, 0, 255), )\r\n\r\n\r\nbab\r\nOut[6]: \r\n  aa_repr_point  ...                                             bb_pic\r\n0     (124, 82)  ...  [[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], ...\r\n1     (142, 71)  ...  [[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], ...\r\n2     (73, 119)  ...  [[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], ...\r\n```\r\n\r\n\r\n\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2004_02_09-.png\"/>\r\n\r\n\r\n\r\n\r\n\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/2022-12-27%2004_01_57-.png\"/>\r\n\r\n\r\n\r\n\r\n```python\r\n# Do you prefer working with dicts instead of DataFrames? \r\ndf.im_get_color_lookup_dict()\r\n{(0,\r\n  0,\r\n  0): array([[  0,   0],\r\n        [  1,   0],\r\n        [  2,   0],\r\n        ...,\r\n        [196, 199],\r\n        [197, 199],\r\n        [198, 199]], dtype=uint16),\r\n (15, 33, 48): array([[199, 199]], dtype=uint16),\r\n (17, 35, 49): array([[131,  88]], dtype=uint16),\r\n (17, 35, 50): array([[ 63, 114]], dtype=uint16),\r\n (17, 36, 53): array([[75, 99]], dtype=uint16),\r\n (17,\r\n  37,\r\n  53): array([[119,  97],\r\n        [129,  91]], dtype=uint16),\r\n (18, 36, 50): array([[126,  94]], dtype=uint16),\r\n (18, 37, 52): array([[125,  35]], dtype=uint16),\r\n (19, 38, 53): array([[ 68, 104]], dtype=uint16),\r\n (19,\r\n  39,\r\n  55): array([[ 36, 124],\r\n        [ 73, 100]], dtype=uint16),\r\n...\r\n```\r\n\r\n\r\n\r\n```python\r\ndf.im_get_image_size()\r\n# Out[7]: [(0, 0, 200, 200)]\r\n```\r\n\r\n\r\n\r\n```python\r\n# Count colors in certain regions\r\ndf.im_get_colors_in_regions_and_count(regions=[(10, 10, 100, 100), (150, 150, 160, 170)])\r\nOut[11]: \r\n     red  green  blue  ...  size_of_area  percentage_of_area                region\r\n0      0      0     0  ...          8100           61.925926    (10, 10, 100, 100)\r\n1     69    132   182  ...          8100            1.790123    (10, 10, 100, 100)\r\n2    255    255   255  ...          8100            1.160494    (10, 10, 100, 100)\r\n3     67    129   179  ...          8100            1.148148    (10, 10, 100, 100)\r\n4     62    123   172  ...          8100            1.135802    (10, 10, 100, 100)\r\n..   ...    ...   ...  ...           ...                 ...                   ...\r\n218   59    110   151  ...          8100            0.012346    (10, 10, 100, 100)\r\n219   59    111   153  ...          8100            0.012346    (10, 10, 100, 100)\r\n220   60    112   154  ...          8100            0.012346    (10, 10, 100, 100)\r\n221   62    111   147  ...          8100            0.012346    (10, 10, 100, 100)\r\n222    0      0     0  ...           200          115.500000  (150, 150, 160, 170)\r\n[223 rows x 7 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\n# You can limit the search region\r\ndf.im_limit_search_areas(areas=[(0, 0, 50, 50), (50, 50, 150, 170)]).im_multicolor_lookup(\r\n    colorlist=[(255, 232, 115), (255, 0, 0), (48, 105, 152)])\r\nOut[12]: \r\n         x    y  red  green  blue\r\n13332  132   66   48    105   152\r\n13337  137   66  255    232   115\r\n13338  138   66  255    232   115\r\n13339  139   66  255    232   115\r\n13340  140   66  255    232   115\r\n    ...  ...  ...    ...   ...\r\n33502  102  167  255      0     0\r\n33503  103  167  255      0     0\r\n33504  104  167  255      0     0\r\n33505  105  167  255      0     0\r\n33506  106  167  255      0     0\r\n[1352 rows x 5 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\n# define regions for every individual color\r\ncolordict = {(255, 0, 0): [(0, 0, 50, 50), (0, 0, 1000, 1000)],\r\n    (255, 232, 115): [(0, 0, 1000, 1000), (500, 500, 502, 502), (900, 900, 1000, 950), ],\r\n    (255, 255, 255): [(0, 0, 1000, 1000), (400, 200, 800, 400)], (0, 176, 111): [(0, 0, 1000, 1000)],\r\n    (57, 59, 61): [(0, 0, 1000, 1000)], (0, 0, 0): [(0, 0, 1000, 1000)], }\r\nregi = df.im_get_coords_of_colors_in_regions(colordict)\r\n\r\n         x    y  red  green  blue\r\n0        0    0    0      0     0\r\n1        1    0    0      0     0\r\n2        2    0    0      0     0\r\n3        3    0    0      0     0\r\n4        4    0    0      0     0\r\n    ...  ...  ...    ...   ...\r\n39995  195  199    0      0     0\r\n39996  196  199    0      0     0\r\n39997  197  199    0      0     0\r\n39998  198  199    0      0     0\r\n39999  199  199    0      0     0\r\n[28789 rows x 5 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\n# You can use a multi index to check individual pixels \r\ndfxy = df.im_xy_as_index()\r\n\r\n         red  green  blue\r\nx   y                    \r\n0   0      0      0     0\r\n    1      0      0     0\r\n    2      0      0     0\r\n    3      0      0     0\r\n    4      0      0     0\r\n      ...    ...   ...\r\n199 195    0      0     0\r\n    196    0      0     0\r\n    197    0      0     0\r\n    198    0      0     0\r\n    199    0      0     0\r\n[40000 rows x 3 columns]\r\n\r\n# Let's get the RGB values using the DataFrame we have just created\r\ndfxy.loc[[(0,100), (100,100), (44,40)]]\r\n\r\nOut[17]: \r\n         red  green  blue\r\nx   y                    \r\n0   100    0      0     0\r\n100 100    0      0     0\r\n44  40     0      0     0\r\n```\r\n\r\n\r\n\r\n```python\r\n# can also be done like that:\r\ncoordlist = [(10, 10), (100, 100), (50, 80)]\r\ncolors_of_coords = df.im_get_colors_of_coords(coordlist)\r\ncolors_of_coords\r\nOut[19]: \r\n         red  green  blue\r\nx   y                    \r\n10  10     0      0     0\r\n100 100    0      0     0\r\n50  80    70    134   184\r\n```\r\n\r\n\r\n\r\n```python\r\nCompare 2 images:\r\npythonlogo = 'https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png'\r\ndf = pd.Q_image2df(pythonlogo)\r\ndf.loc[df.im_multicolor_lookup(get_list_of_all_colors_in_range((0,0,0), (10,10,10))).index, ['red', 'green', 'blue']] = [255,255,0] \r\npythonlogo = 'https://github.com/hansalemaos/screenshots/raw/main/colorfind1.png'\r\ndf2 = pd.Q_image2df(pythonlogo)\r\ndf2.im_compare_2_images(df)\r\nOut[23]: \r\n       pic_index    x    y  r1  g1  b1   r2   g2  b2\r\n0              0    0    0   0   0   0  255  255   0\r\n1              1    1    0   0   0   0  255  255   0\r\n2              2    2    0   0   0   0  255  255   0\r\n3              3    3    0   0   0   0  255  255   0\r\n4              4    4    0   0   0   0  255  255   0\r\n          ...  ...  ...  ..  ..  ..  ...  ...  ..\r\n27510      39995  195  199   0   0   0  255  255   0\r\n27511      39996  196  199   0   0   0  255  255   0\r\n27512      39997  197  199   0   0   0  255  255   0\r\n27513      39998  198  199   0   0   0  255  255   0\r\n27514      39999  199  199   0   0   0  255  255   0\r\n[27515 rows x 9 columns]\r\n```\r\n\r\n\r\n```python\r\n# If you want to do additional stuff with OpenCV:\r\ndf.im_xy_to_cv2_coords()\r\nOut[28]: \r\narray([[[  0,   0],\r\n        [  1,   0],\r\n        [  2,   0],\r\n        ...,\r\n        [197, 199],\r\n        [198, 199],\r\n        [199, 199]]])\r\n```\r\n\r\n\r\n\r\n```python\r\ndf.im_singlecolor_lookup((255,255,0))\r\nOut[45]: \r\n         x    y  red  green  blue\r\n0        0    0  255    255     0\r\n1        1    0  255    255     0\r\n2        2    0  255    255     0\r\n3        3    0  255    255     0\r\n4        4    0  255    255     0\r\n    ...  ...  ...    ...   ...\r\n39995  195  199  255    255     0\r\n39996  196  199  255    255     0\r\n39997  197  199  255    255     0\r\n39998  198  199  255    255     0\r\n39999  199  199  255    255     0\r\n[27515 rows x 5 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\ndf.im_get_closest_colors([(10,3,4)])\r\nOut[55]: \r\n       r    g    b      rating         rgb\r\n0      0    0    0   11.179688  (10, 3, 4)\r\n1     15   33   48   53.500000  (10, 3, 4)\r\n2     17   35   49   55.656250  (10, 3, 4)\r\n3     17   35   50   56.468750  (10, 3, 4)\r\n4     18   36   50   57.187500  (10, 3, 4)\r\n..   ...  ...  ...         ...         ...\r\n712  250  242  218  400.750000  (10, 3, 4)\r\n713  252  247  230  411.250000  (10, 3, 4)\r\n714  241  244  246  412.250000  (10, 3, 4)\r\n715  253  251  243  421.500000  (10, 3, 4)\r\n716  255  255  255  432.000000  (10, 3, 4)\r\n[717 rows x 5 columns]\r\n```\r\n\r\n\r\n\r\n```python\r\nget_list_of_all_colors_in_range((0,0,0), (3,4,3))\r\n\r\nOut[59]: \r\n[(0, 0, 0),\r\n (0, 0, 1),\r\n (0, 0, 2),\r\n (0, 0, 3),\r\n (0, 1, 0),\r\n (0, 1, 1),\r\n (0, 1, 2),\r\n (0, 1, 3),\r\n (0, 2, 0),\r\n (0, 2, 1),\r\n (0, 2, 2),\r\n (0, 2, 3),\r\n (0, 3, 0),\r\n```\r\n\r\n\r\n\r\n\r\n```python\r\ndfr = df.im_rgb_as_index()\r\nOut[65]: \r\n                  x    y\r\nred green blue          \r\n0   0     0       0    0\r\n          0       1    0\r\n          0       2    0\r\n          0       3    0\r\n          0       4    0\r\n             ...  ...\r\n255 255   255   120  155\r\n          255   121  155\r\n          255   117  156\r\n          255   118  156\r\n          255   119  156\r\n[40000 rows x 2 columns]\r\n\r\n\r\n#Now you can use dfr.loc to get the coordinates\r\ndfr.loc[(17,37,53)]\r\ndfr.loc[ (39,83,119)]\r\n```\r\n\r\n\r\n\r\n```python\r\n# finds all colors that only exist in the region and nowhere else in the picture \r\ndf.im_get_unique_colors_in_region([(0,0,100,100)])\r\nOut[72]: \r\n        x   y  red  green  blue\r\n18432  32  92   73    137   188\r\n18433  33  92   73    137   187\r\n18434  34  92   72    136   187\r\n18435  35  92   72    136   186\r\n18436  36  92   72    135   186\r\n    ..  ..  ...    ...   ...\r\n14255  55  71   71    135   186\r\n14256  56  71   71    135   185\r\n14257  57  71   71    134   185\r\n12266  66  61   53    102   140\r\n18431  31  92   59    111   153\r\n[845 rows x 5 columns]\r\n```\r\n\r\n```python\r\n# finds all colors that are in the region and somewhere else in the picture \r\ndf.im_get_not_unique_colors_in_region([(0,0,100,100)])\r\nOut[73]: \r\n         x    y  red  green  blue\r\n0        0    0    0      0     0\r\n1        1    0    0      0     0\r\n2        2    0    0      0     0\r\n3        3    0    0      0     0\r\n4        4    0    0      0     0\r\n    ...  ...  ...    ...   ...\r\n20096   96  100    0      0     0\r\n20097   97  100    0      0     0\r\n20098   98  100    0      0     0\r\n20099   99  100    0      0     0\r\n20100  100  100    0      0     0\r\n[9356 rows x 5 columns]\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Uses pandas/numpy/numexpr for operations on pictures - very fast",
    "version": "0.11",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/a_pandas_ex_image_tools"
    },
    "split_keywords": [
        "pandas",
        "opencv",
        "cv2",
        "images",
        "pixels",
        "detection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcbaec3e6b9ae4bd6760c7685a9d1ffbba8eccdac58234e71d107dcaab983d85",
                "md5": "c6d301069bc0f23105119bc2b5b238a2",
                "sha256": "841042235dd3d167230323a2981eadcfa57b311129fee662d8a8983ddd2324c8"
            },
            "downloads": -1,
            "filename": "a_pandas_ex_image_tools-0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c6d301069bc0f23105119bc2b5b238a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 68879,
            "upload_time": "2023-09-05T21:20:06",
            "upload_time_iso_8601": "2023-09-05T21:20:06.422026Z",
            "url": "https://files.pythonhosted.org/packages/bc/ba/ec3e6b9ae4bd6760c7685a9d1ffbba8eccdac58234e71d107dcaab983d85/a_pandas_ex_image_tools-0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e88f0ee1800d9ebb4f2e883faa7aff7460bf8e57f53e71b38e17fcb4e9b6b8ba",
                "md5": "d8e0719034411ee08510d797e23135be",
                "sha256": "e851a4d8cc9652f43c4ad05843b75191d2d54d9bfd882a77ae14c5ec7e76471b"
            },
            "downloads": -1,
            "filename": "a_pandas_ex_image_tools-0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "d8e0719034411ee08510d797e23135be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 68669,
            "upload_time": "2023-09-05T21:20:08",
            "upload_time_iso_8601": "2023-09-05T21:20:08.306940Z",
            "url": "https://files.pythonhosted.org/packages/e8/8f/0ee1800d9ebb4f2e883faa7aff7460bf8e57f53e71b38e17fcb4e9b6b8ba/a_pandas_ex_image_tools-0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-05 21:20:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "a_pandas_ex_image_tools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "a-pandas-ex-image-tools"
}
        
Elapsed time: 0.14078s