kandi background
Explore Kits

Pillow | The friendly PIL fork | Computer Vision library

 by   python-pillow Python Version: 9.1.0 License: Non-SPDX

 by   python-pillow Python Version: 9.1.0 License: Non-SPDX

Download this library from

kandi X-RAY | Pillow Summary

Pillow is a Python library typically used in Artificial Intelligence, Computer Vision, Deep Learning applications. Pillow has no bugs, it has no vulnerabilities, it has build file available and it has medium support. However Pillow has a Non-SPDX License. You can install using 'pip install Pillow' or download it from GitHub, PyPI.
The Python Imaging Library adds image processing capabilities to your Python interpreter. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. The core image library is designed for fast access to data stored in a few basic pixel formats. It should provide a solid foundation for a general image processing tool.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • Pillow has a medium active ecosystem.
  • It has 9695 star(s) with 1832 fork(s). There are 211 watchers for this library.
  • There were 1 major release(s) in the last 6 months.
  • There are 96 open issues and 2371 have been closed. On average issues are closed in 50 days. There are 31 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of Pillow is 9.1.0
Pillow Support
Best in #Computer Vision
Average in #Computer Vision
Pillow Support
Best in #Computer Vision
Average in #Computer Vision

quality kandi Quality

  • Pillow has 0 bugs and 0 code smells.
Pillow Quality
Best in #Computer Vision
Average in #Computer Vision
Pillow Quality
Best in #Computer Vision
Average in #Computer Vision

securitySecurity

  • Pillow has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • Pillow code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
Pillow Security
Best in #Computer Vision
Average in #Computer Vision
Pillow Security
Best in #Computer Vision
Average in #Computer Vision

license License

  • Pillow has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
Pillow License
Best in #Computer Vision
Average in #Computer Vision
Pillow License
Best in #Computer Vision
Average in #Computer Vision

buildReuse

  • Pillow releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Pillow saves you 19159 person hours of effort in developing the same functionality from scratch.
  • It has 40016 lines of code, 3149 functions and 279 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
Pillow Reuse
Best in #Computer Vision
Average in #Computer Vision
Pillow Reuse
Best in #Computer Vision
Average in #Computer Vision
Top functions reviewed by kandi - BETA

kandi has reviewed Pillow and discovered the below as its top functions. This is intended to give you an instant insight into Pillow implemented functionality, and help decide if they suit your requirements.

  • Builds the list of supported extensions .
  • Sets up attributes .
  • Convert the image .
  • Read the bitmap .
  • Load the default font data .
  • Save an image .
  • Write multiple frames to fp .
  • Extract a value from the data .
  • Add application marker .
  • Compute the regular polygon vertices .

Pillow Key Features

The friendly PIL fork (Python Imaging Library)

Improve speed of getpixel and putpixel

copy iconCopydownload iconDownload
from PIL import Image
import numba as nb
import numpy as np

@nb.njit(parallel=True)
def new_RainbowFilter(img):    
    intensity = img.sum(axis=-1)
    row , col = img.shape[:2]
    for r in nb.prange(row):
        for c in nb.prange(col):
            i = (intensity[r,c] + r + c)
            x = 1 - abs(((i / 60) % 2) - 1)
            i %= 360
            res = np.zeros(3)
            if   (i >= 0   and i < 60 ): res = np.array([1, x, 0])
            elif (i >= 60  and i < 120): res = np.array([x, 1, 0])
            elif (i >= 120 and i < 180): res = np.array([0, 1, x])
            elif (i >= 180 and i < 240): res = np.array([0, x, 1])
            elif (i >= 240 and i < 300): res = np.array([x, 0, 1])
            elif (i >= 300 and i < 360): res = np.array([1, 0, x])
            img[r,c] = res * 255
    return img


im = Image.open('cat.jpg')
img = np.asarray(im)
img = new_RainbowFilter(img)
im = Image.fromarray(img)
im.save('rainbow_im.png')
-----------------------
#!/usr/bin/env python3

from PIL import Image
import numba as nb
import numpy as np

def Rainbow(i):
    x = 1 - abs(((i / 60) % 2) - 1)
    i %= 360
    if (i >= 0   and i < 60 ): r,g,b = 1, x, 0
    if (i >= 60  and i < 120): r,g,b = x, 1, 0
    if (i >= 120 and i < 180): r,g,b = 0, 1, x
    if (i >= 180 and i < 240): r,g,b = 0, x, 1
    if (i >= 240 and i < 300): r,g,b = x, 0, 1
    if (i >= 300 and i < 360): r,g,b = 1, 0, x
    res = (int(r * 255), int(g * 255), int(b * 255))
    return res

def RainbowFilter(img):
    for x in range(img.size[0]):
        for y in range(img.size[1]):
            intensity = sum(img.getpixel((x, y)))
            img.putpixel((x, y), Rainbow(intensity + x + y))
    return img

@nb.njit(parallel=True)
def imahdi(img):    
    intensity = img.sum(axis=-1)
    row , col = img.shape[:2]
    for r in nb.prange(row):
        for c in nb.prange(col):
            i = (intensity[r,c] + r + c)
            x = 1 - abs(((i / 60) % 2) - 1)
            i %= 360
            res = np.zeros(3)
            if   (i >= 0   and i < 60 ): res = np.array([1, x, 0])
            elif (i >= 60  and i < 120): res = np.array([x, 1, 0])
            elif (i >= 120 and i < 180): res = np.array([0, 1, x])
            elif (i >= 180 and i < 240): res = np.array([0, x, 1])
            elif (i >= 240 and i < 300): res = np.array([x, 0, 1])
            elif (i >= 300 and i < 360): res = np.array([1, 0, x])
            img[r,c] = res * 255
    return img

@nb.njit(parallel=True)
def mark(img):    
    intensity = img.sum(axis=-1)
    row , col = img.shape[:2]
    # Create zeroed result image
    res = np.zeros_like(img)
    for r in nb.prange(row):
        # Only make outer loop parallel else inner one will make more threads than cores
        for c in range(col):
            i = (intensity[r,c] + r + c)
            x = 1 - abs(((i / 60) % 2) - 1)
            x = int(x * 255)
            i %= 360
            # Split the problem space in half in one test - like binary search
            if i < 180:
               if i < 60:
                  # Don't create whole new array here 
                  # Don't assign zeroes, array is empty already
                  res[r,c,0] = 255
                  res[r,c,1] = x
               elif i < 120:
                  res[r,c,0] = x
                  res[r,c,1] = 255
               else:
                  res[r,c,1] = 255
                  res[r,c,2] = x
            else:
               if i < 240:
                  res[r,c,1] = x
                  res[r,c,2] = 255
               elif i < 300:
                  res[r,c,0] = x
                  res[r,c,2] = 255
               else:
                  res[r,c,0] = 255
                  res[r,c,2] = x
    return res

orig = Image.open('cat.jpg')
res  = RainbowFilter(orig)
res.save('result.png')

im  = np.asarray(orig)
res = imahdi(im)
Image.fromarray(res).save('imahdi.ppm')

res = mark(im)
Image.fromarray(res).save('mark.ppm')
In [17]: %timeit res = RainbowFilter(orig)                                      
11.7 s ± 80 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [18]: %timeit res = imahdi(im)                                               
1.52 s ± 4.81 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [13]: %timeit res=mark(im)                                                   
35.6 ms ± 928 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
-----------------------
#!/usr/bin/env python3

from PIL import Image
import numba as nb
import numpy as np

def Rainbow(i):
    x = 1 - abs(((i / 60) % 2) - 1)
    i %= 360
    if (i >= 0   and i < 60 ): r,g,b = 1, x, 0
    if (i >= 60  and i < 120): r,g,b = x, 1, 0
    if (i >= 120 and i < 180): r,g,b = 0, 1, x
    if (i >= 180 and i < 240): r,g,b = 0, x, 1
    if (i >= 240 and i < 300): r,g,b = x, 0, 1
    if (i >= 300 and i < 360): r,g,b = 1, 0, x
    res = (int(r * 255), int(g * 255), int(b * 255))
    return res

def RainbowFilter(img):
    for x in range(img.size[0]):
        for y in range(img.size[1]):
            intensity = sum(img.getpixel((x, y)))
            img.putpixel((x, y), Rainbow(intensity + x + y))
    return img

@nb.njit(parallel=True)
def imahdi(img):    
    intensity = img.sum(axis=-1)
    row , col = img.shape[:2]
    for r in nb.prange(row):
        for c in nb.prange(col):
            i = (intensity[r,c] + r + c)
            x = 1 - abs(((i / 60) % 2) - 1)
            i %= 360
            res = np.zeros(3)
            if   (i >= 0   and i < 60 ): res = np.array([1, x, 0])
            elif (i >= 60  and i < 120): res = np.array([x, 1, 0])
            elif (i >= 120 and i < 180): res = np.array([0, 1, x])
            elif (i >= 180 and i < 240): res = np.array([0, x, 1])
            elif (i >= 240 and i < 300): res = np.array([x, 0, 1])
            elif (i >= 300 and i < 360): res = np.array([1, 0, x])
            img[r,c] = res * 255
    return img

@nb.njit(parallel=True)
def mark(img):    
    intensity = img.sum(axis=-1)
    row , col = img.shape[:2]
    # Create zeroed result image
    res = np.zeros_like(img)
    for r in nb.prange(row):
        # Only make outer loop parallel else inner one will make more threads than cores
        for c in range(col):
            i = (intensity[r,c] + r + c)
            x = 1 - abs(((i / 60) % 2) - 1)
            x = int(x * 255)
            i %= 360
            # Split the problem space in half in one test - like binary search
            if i < 180:
               if i < 60:
                  # Don't create whole new array here 
                  # Don't assign zeroes, array is empty already
                  res[r,c,0] = 255
                  res[r,c,1] = x
               elif i < 120:
                  res[r,c,0] = x
                  res[r,c,1] = 255
               else:
                  res[r,c,1] = 255
                  res[r,c,2] = x
            else:
               if i < 240:
                  res[r,c,1] = x
                  res[r,c,2] = 255
               elif i < 300:
                  res[r,c,0] = x
                  res[r,c,2] = 255
               else:
                  res[r,c,0] = 255
                  res[r,c,2] = x
    return res

orig = Image.open('cat.jpg')
res  = RainbowFilter(orig)
res.save('result.png')

im  = np.asarray(orig)
res = imahdi(im)
Image.fromarray(res).save('imahdi.ppm')

res = mark(im)
Image.fromarray(res).save('mark.ppm')
In [17]: %timeit res = RainbowFilter(orig)                                      
11.7 s ± 80 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [18]: %timeit res = imahdi(im)                                               
1.52 s ± 4.81 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [13]: %timeit res=mark(im)                                                   
35.6 ms ± 928 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

Find the minimum plane of the maximum number of black pixels in the bottom image. Find the peak of the black pixels for the top image

copy iconCopydownload iconDownload
import numpy as np
import cv2

# read image
img = cv2.imread("img.png")

# Note that there is a 2 pixel tall white line at the bottom
# Note that there is columns of black at the left and right sides

# convert to grayscale
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# threshold
img = cv2.threshold(img,0,255,cv2.THRESH_BINARY)[1]

# flip vertically
img = cv2.flip(img, 0)

# remove 2 pixels at the top
img = img[2:, :]

# add one pixel row of white at bottom
img = cv2.copyMakeBorder(img, 0, 2, 0, 0, cv2.BORDER_CONSTANT, value=255)

# find max along each column
max = np.argmax(img, axis=0)
print(max.shape)

print(max)

cv2.imshow('flipped',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
(709,)
[112 112 112 112  32  32  32  32  32  32  32  32  32  32  32  32  32  32
  31  31  31  31  31  31  31  31  31  31  30  30  30  30  30  30  30  30
  30  30  30  30  30  30  30  30  30  30  30  31  31  31  31  31  31  31
  31  31  31  31  31  31  31  31  31  30  30  30  30  30  30  30  30  30
  30  30  30  31  31  32  32  33  33  34  35  35  36  36  36  36  36  36
  36  36  36  36  36  36  36  36  37  37  38  38  39  39  39  40  40  40
  41  41  43  43  44  45  45  46  46  46  46  46  46  46  46  46  46  46
  46  46  46  46  46  46  46  46  46  46  46  46  46  45  45  45  45  44
  44  44  44  44  44  44  44  44  44  44  44  44  43  43  43  43  43  43
  43  43  43  43  43  43  43  44  44  44  44  44  44  44  44  43  43  43
  42  42  42  42  42  42  42  42  42  42  41  41  40  40  40  40  40  40
  40  40  40  40  40  40  40  40  40  40  40  40  39  39  39  39  39  39
  39  39  39  39  39  39  39  39  39  39  39  39  38  38  37  37  37  37
  37  37  37  36  36  36  36  36  35  35  35  34  34  34  34  34  34  34
  34  34  33  33  32  32  32  32  32  32  32  32  32  32  32  32  32  32
  33  33  34  34  35  35  36  37  37  37  37  38  38  38  38  38  38  38
  38  38  38  38  38  38  38  39  39  40  40  40  40  40  39  39  39  39
  39  39  38  38  38  37  37  37  37  37  37  37  37  37  37  37  37  37
  37  38  38  38  39  40  40  41  41  41  39  39  38  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  38  38
  38  39  39  39  39  39  39  39  39  41  41  41  41  41  41  41  41  41
  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41
  40  40  40  40  40  40  40  40  40  40  39  39  38  38  37  37  37  37
  36  36  36  36  36  36  35  35  34  34  34  33  33  33  32  31  31  31
  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31
  31  31  31  31  31  31  31  31  30  30  29  29  29  28  28  28  28  27
  27  26  26  26  26  26  26  26  26  26  26  26  26  26  26  27  27  27
  27  27  27  27  27  27  28  28  28  28  28  28  28  28  28  28  28  28
  28  28  28  28  28  28  28  28  28  28  28  28  28  28  29  29  29  29
  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29
  29  28  28  27  27  27  27  27  27  27  27  27  27  27  27  27  28  28
  28  28  29  29  30  30  30  31  31  32  32  33  33  34  34  35  35  36
  36  36  37  37  37  38  38  39  39  39  39  39  39  39  39  39  39  39
  39  38  38  37  37  37  37  37  37  36  36  35  35  35  35  35  35  35
  35  35  35  35  35  35  35  35  35  35  35  36  36  36  36  36  36  36
  36  36  36  36  36  36  37  37  37  37  37  37  37  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  38  38  38  39  39
  39  39  39  40 112 112 112]
-----------------------
import numpy as np
import cv2

# read image
img = cv2.imread("img.png")

# Note that there is a 2 pixel tall white line at the bottom
# Note that there is columns of black at the left and right sides

# convert to grayscale
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# threshold
img = cv2.threshold(img,0,255,cv2.THRESH_BINARY)[1]

# flip vertically
img = cv2.flip(img, 0)

# remove 2 pixels at the top
img = img[2:, :]

# add one pixel row of white at bottom
img = cv2.copyMakeBorder(img, 0, 2, 0, 0, cv2.BORDER_CONSTANT, value=255)

# find max along each column
max = np.argmax(img, axis=0)
print(max.shape)

print(max)

cv2.imshow('flipped',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
(709,)
[112 112 112 112  32  32  32  32  32  32  32  32  32  32  32  32  32  32
  31  31  31  31  31  31  31  31  31  31  30  30  30  30  30  30  30  30
  30  30  30  30  30  30  30  30  30  30  30  31  31  31  31  31  31  31
  31  31  31  31  31  31  31  31  31  30  30  30  30  30  30  30  30  30
  30  30  30  31  31  32  32  33  33  34  35  35  36  36  36  36  36  36
  36  36  36  36  36  36  36  36  37  37  38  38  39  39  39  40  40  40
  41  41  43  43  44  45  45  46  46  46  46  46  46  46  46  46  46  46
  46  46  46  46  46  46  46  46  46  46  46  46  46  45  45  45  45  44
  44  44  44  44  44  44  44  44  44  44  44  44  43  43  43  43  43  43
  43  43  43  43  43  43  43  44  44  44  44  44  44  44  44  43  43  43
  42  42  42  42  42  42  42  42  42  42  41  41  40  40  40  40  40  40
  40  40  40  40  40  40  40  40  40  40  40  40  39  39  39  39  39  39
  39  39  39  39  39  39  39  39  39  39  39  39  38  38  37  37  37  37
  37  37  37  36  36  36  36  36  35  35  35  34  34  34  34  34  34  34
  34  34  33  33  32  32  32  32  32  32  32  32  32  32  32  32  32  32
  33  33  34  34  35  35  36  37  37  37  37  38  38  38  38  38  38  38
  38  38  38  38  38  38  38  39  39  40  40  40  40  40  39  39  39  39
  39  39  38  38  38  37  37  37  37  37  37  37  37  37  37  37  37  37
  37  38  38  38  39  40  40  41  41  41  39  39  38  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  38  38
  38  39  39  39  39  39  39  39  39  41  41  41  41  41  41  41  41  41
  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41  41
  40  40  40  40  40  40  40  40  40  40  39  39  38  38  37  37  37  37
  36  36  36  36  36  36  35  35  34  34  34  33  33  33  32  31  31  31
  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31  31
  31  31  31  31  31  31  31  31  30  30  29  29  29  28  28  28  28  27
  27  26  26  26  26  26  26  26  26  26  26  26  26  26  26  27  27  27
  27  27  27  27  27  27  28  28  28  28  28  28  28  28  28  28  28  28
  28  28  28  28  28  28  28  28  28  28  28  28  28  28  29  29  29  29
  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29
  29  28  28  27  27  27  27  27  27  27  27  27  27  27  27  27  28  28
  28  28  29  29  30  30  30  31  31  32  32  33  33  34  34  35  35  36
  36  36  37  37  37  38  38  39  39  39  39  39  39  39  39  39  39  39
  39  38  38  37  37  37  37  37  37  36  36  35  35  35  35  35  35  35
  35  35  35  35  35  35  35  35  35  35  35  36  36  36  36  36  36  36
  36  36  36  36  36  36  37  37  37  37  37  37  37  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37  37
  37  37  37  37  37  37  37  37  37  37  37  37  37  38  38  38  39  39
  39  39  39  40 112 112 112]

unable to install pyodbc using python 3.10 in windows 10

copy iconCopydownload iconDownload
pip install pyodbc‑4.0.32‑cp310‑cp310‑win_amd64.whl
-----------------------
python -m pip install <Path of downloaded file>.whl

Colab: (0) UNIMPLEMENTED: DNN library is not found

copy iconCopydownload iconDownload
!pip install tensorflow==2.7.0
-----------------------
'tensorflow==2.7.0',
'tf-models-official==2.7.0',
'tensorflow_io==0.23.1',

How to install local package with conda

copy iconCopydownload iconDownload
package:
  name: jive
  version: "0.2.1"

source:
  path: .

build:
  script: python -m pip install --no-deps --ignore-installed .

requirements:
  host:
     - python
     - pip
     - setuptools
  run:
     - python
     - numpy
     - pandas
     - scipy
     - seaborn
     - matplotlib
     - scikit-learn
     - statsmodels
     - joblib
     - bokeh

ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects

copy iconCopydownload iconDownload
apt-get install sox ffmpeg libcairo2 libcairo2-dev
apt-get install texlive-full
pip3 install manimlib  # or pip install manimlib
pip3 install manimce  # or pip install manimce
-----------------------
apt-get install sox ffmpeg libcairo2 libcairo2-dev
apt-get install texlive-full
pip3 install manimlib  # or pip install manimlib
pip3 install manimce  # or pip install manimce

reticulate segfaults with call to plt.plot()

copy iconCopydownload iconDownload
reticulate::virtualenv_create(
  envname = "./venv",
  packages = c("matplotlib")
)

system2("./venv/bin/pip3", c("install",
                             "--no-binary='numpy'",
                             "numpy",
                             "--ignore-installed"))

reticulate::use_virtualenv("./venv")

reticulate::py_run_string("import matplotlib.pyplot as plt;plt.plot([1, 2, 3], [1, 2, 3])")
FROM rocker/r-ver:latest

RUN apt update && apt install -y python3 python3-dev python3-venv

RUN install2.r --error reticulate

# Create a venv
RUN python3 -m venv /root/venv

# Compile numpy from source into venv
RUN /root/venv/bin/pip3 install --no-binary="numpy" numpy --ignore-installed

COPY test.R /root/
reticulate::virtualenv_install(
  envname = "/root/venv",
  packages = c("matplotlib")
)

reticulate::use_virtualenv("/root/venv")

reticulate::py_run_string("import matplotlib.pyplot as plt;plt.plot([1, 2, 3], [1, 2, 3])")
-----------------------
reticulate::virtualenv_create(
  envname = "./venv",
  packages = c("matplotlib")
)

system2("./venv/bin/pip3", c("install",
                             "--no-binary='numpy'",
                             "numpy",
                             "--ignore-installed"))

reticulate::use_virtualenv("./venv")

reticulate::py_run_string("import matplotlib.pyplot as plt;plt.plot([1, 2, 3], [1, 2, 3])")
FROM rocker/r-ver:latest

RUN apt update && apt install -y python3 python3-dev python3-venv

RUN install2.r --error reticulate

# Create a venv
RUN python3 -m venv /root/venv

# Compile numpy from source into venv
RUN /root/venv/bin/pip3 install --no-binary="numpy" numpy --ignore-installed

COPY test.R /root/
reticulate::virtualenv_install(
  envname = "/root/venv",
  packages = c("matplotlib")
)

reticulate::use_virtualenv("/root/venv")

reticulate::py_run_string("import matplotlib.pyplot as plt;plt.plot([1, 2, 3], [1, 2, 3])")
-----------------------
reticulate::virtualenv_create(
  envname = "./venv",
  packages = c("matplotlib")
)

system2("./venv/bin/pip3", c("install",
                             "--no-binary='numpy'",
                             "numpy",
                             "--ignore-installed"))

reticulate::use_virtualenv("./venv")

reticulate::py_run_string("import matplotlib.pyplot as plt;plt.plot([1, 2, 3], [1, 2, 3])")
FROM rocker/r-ver:latest

RUN apt update && apt install -y python3 python3-dev python3-venv

RUN install2.r --error reticulate

# Create a venv
RUN python3 -m venv /root/venv

# Compile numpy from source into venv
RUN /root/venv/bin/pip3 install --no-binary="numpy" numpy --ignore-installed

COPY test.R /root/
reticulate::virtualenv_install(
  envname = "/root/venv",
  packages = c("matplotlib")
)

reticulate::use_virtualenv("/root/venv")

reticulate::py_run_string("import matplotlib.pyplot as plt;plt.plot([1, 2, 3], [1, 2, 3])")

django rest Error - AttributeError: module 'collections' has no attribute 'MutableMapping'

copy iconCopydownload iconDownload
Warning (from warnings module):
  File "<pyshell#1>", line 1
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
FROM python:3.9.7-alpine3.14

...
-----------------------
Warning (from warnings module):
  File "<pyshell#1>", line 1
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
FROM python:3.9.7-alpine3.14

...

Could not find a version that satisfies the requirement psycopg2

copy iconCopydownload iconDownload
  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update
    - apk add -q --update --no-cache postgresql-dev musl-dev
  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update
    - apk add -q --no-cache postgresql-dev gcc python3-dev musl-dev
-----------------------
  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update
    - apk add -q --update --no-cache postgresql-dev musl-dev
  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update
    - apk add -q --no-cache postgresql-dev gcc python3-dev musl-dev

Gitlab CI: Failed building wheel for opencv-python

copy iconCopydownload iconDownload
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.9 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.9/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
  15 | #include <ffi.h>
    |          ^~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
apk add libffi-dev 
-----------------------
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.9 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.9/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
  15 | #include <ffi.h>
    |          ^~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
apk add libffi-dev 

Community Discussions

Trending Discussions on Pillow
  • Improve speed of getpixel and putpixel
  • Find the minimum plane of the maximum number of black pixels in the bottom image. Find the peak of the black pixels for the top image
  • unable to install pyodbc using python 3.10 in windows 10
  • Colab: (0) UNIMPLEMENTED: DNN library is not found
  • How to install local package with conda
  • ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects
  • reticulate segfaults with call to plt.plot()
  • django rest Error - AttributeError: module 'collections' has no attribute 'MutableMapping'
  • Can't deploy streamlit app on share.streamlit.io
  • Could not find a version that satisfies the requirement psycopg2
Trending Discussions on Pillow

QUESTION

Improve speed of getpixel and putpixel

Asked 2022-Apr-04 at 10:13

Using PIL, I'm applying a rainbow filter to the given image using getpixel and setpixel. One issue, this method is very slow. It takes around 10 seconds to finish one image.

def Rainbow(i):
    x = 1 - abs(((i / 60) % 2) - 1)
    i %= 360
    if (i >= 0   and i < 60 ): r,g,b = 1, x, 0
    if (i >= 60  and i < 120): r,g,b = x, 1, 0
    if (i >= 120 and i < 180): r,g,b = 0, 1, x
    if (i >= 180 and i < 240): r,g,b = 0, x, 1
    if (i >= 240 and i < 300): r,g,b = x, 0, 1
    if (i >= 300 and i < 360): r,g,b = 1, 0, x
    res = (int(r * 255), int(g * 255), int(b * 255))
    return res
def RainbowFilter(img):
    for x in range(img.size[0]):
        for y in range(img.size[1]):
            intensity = sum(img.getpixel((x, y)))
            img.putpixel((x, y), Rainbow(intensity + x + y))
    return img

im = Image.open('cat.jpg')
rainbow_im = RainbowFilter(im)
rainbow_im.save('rainbow_im.png')

Input image Result Can you help me improve my specific algorithm, using exclusively Numpy or Pillow features, to resolve the issue mentioned?

ANSWER

Answered 2022-Apr-03 at 15:21

You can convert image to NumPy.array then use numba for improving speed like below:

from PIL import Image
import numba as nb
import numpy as np

@nb.njit(parallel=True)
def new_RainbowFilter(img):    
    intensity = img.sum(axis=-1)
    row , col = img.shape[:2]
    for r in nb.prange(row):
        for c in nb.prange(col):
            i = (intensity[r,c] + r + c)
            x = 1 - abs(((i / 60) % 2) - 1)
            i %= 360
            res = np.zeros(3)
            if   (i >= 0   and i < 60 ): res = np.array([1, x, 0])
            elif (i >= 60  and i < 120): res = np.array([x, 1, 0])
            elif (i >= 120 and i < 180): res = np.array([0, 1, x])
            elif (i >= 180 and i < 240): res = np.array([0, x, 1])
            elif (i >= 240 and i < 300): res = np.array([x, 0, 1])
            elif (i >= 300 and i < 360): res = np.array([1, 0, x])
            img[r,c] = res * 255
    return img


im = Image.open('cat.jpg')
img = np.asarray(im)
img = new_RainbowFilter(img)
im = Image.fromarray(img)
im.save('rainbow_im.png')

Source https://stackoverflow.com/questions/71724930

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install Pillow

You can install using 'pip install Pillow' or download it from GitHub, PyPI.
You can use Pillow like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Computer Vision Libraries with Highest Support
Compare Computer Vision Libraries with Highest Security
Compare Computer Vision Libraries with Permissive License
Compare Computer Vision Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.