Best Image Processing Library For Android

by -68 views

According to IDC, digital data volition skyrocket upward to 175 zettabytes, and the huge part of this information is images. Information scientists need to (pre) process these images before feeding them into any machine learning models. They accept to practice the important (and sometimes muddied) work before the fun part begins.

To process a large amount of data with efficiency and speed without compromising the results data scientists need to use image processing tools for machine learning and deep learning tasks.

In this article, I am going to list out the near useful image processing libraries in Python which are beingness used heavily in auto learning tasks.

1. OpenCV

OpenCV
is an open-source library that was adult past Intel in the yr 2000. Information technology is generally used in figurer vision tasks such equally object detection, confront detection, face recognition, image segmentation, etc but also contains a lot of useful functions that you may need in ML.

Gray-scaling

        import
        cv2
        as
        cv
        import
        numpy
        as
        np
        import
        matplotlib.pyplot
        as
        plt  img = cv.imread('goku.jpeg') gray_image = cv.cvtColor(img, cv.COLOR_BGR2GRAY)  fig, ax = plt.subplots(1,
        two, figsize=(16,
        eight)) fig.tight_layout()  ax[0].imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB)) ax[0].set_title("Original")  ax[i].imshow(cv.cvtColor(gray_image, cv.COLOR_BGR2RGB)) ax[1].set_title("Grayscale") plt.show()
      

A colored image consists of iii color channels where a gray image only consists of i Color channel which carries intensity information for each pixel showing the image as black-and-white.

The following code separates each colour aqueduct:

        import
        cv2
        as
        cv
        import
        numpy
        as
        np
        import
        matplotlib.pyplot
        as
        plt   img = cv.imread('goku.jpeg') b, thousand, r = cv.dissever(img)  fig, ax = plt.subplots(1,
        iii, figsize=(16,
        viii)) fig.tight_layout()  ax[0].imshow(cv.cvtColor(r, cv.COLOR_BGR2RGB)) ax[0].set_title("Blood-red")  ax[1].imshow(cv.cvtColor(g, cv.COLOR_BGR2RGB)) ax[1].set_title("Green")  ax[2].imshow(cv.cvtColor(b, cv.COLOR_BGR2RGB)) ax[2].set_title("Blue")
      
Gray-scaling effect

Image translation

        import
        cv2
        as
        cv
        import
        numpy
        equally
        np
        import
        matplotlib.pyplot
        as
        plt  epitome = cv.imread("pics/goku.jpeg") h, w = image.shape[:2]  half_height, half_width = h//4, w//8
        transition_matrix = np.float32([[1,
        0, half_width],                                [0,
        1, half_height]])  img_transition = cv.warpAffine(image, transition_matrix, (w, h))  plt.imshow(cv.cvtColor(img_transition, cv.COLOR_BGR2RGB)) plt.title("Translation") plt.bear witness()
      
image translation

Above code translates an prototype from i coordinate to a different coordinate.

Image rotation

        import
        cv2
        equally
        cv
        import
        numpy
        as
        np
        import
        matplotlib.pyplot
        every bit
        plt  image = cv.imread("pics/goku.jpeg")  h, westward = image.shape[:2]   rotation_matrix = cv.getRotationMatrix2D((w/two,h/2),
        -180,
        0.5)  rotated_image = cv.warpAffine(image, rotation_matrix, (w, h))  plt.imshow(cv.cvtColor(rotated_image, cv.COLOR_BGR2RGB)) plt.championship("Rotation") plt.evidence()
image rotation

Rotation of an image for the X or Y-axis.

Scaling and resizing

        import
        cv2
        every bit
        cv
        import
        numpy
        as
        np
        import
        matplotlib.pyplot
        as
        plt  image = cv.imread("pics/goku.jpeg")  fig, ax = plt.subplots(one,
        3, figsize=(sixteen,
        8))   image_scaled = cv.resize(image,
        None, fx=0.15, fy=0.15) ax[0].imshow(cv.cvtColor(image_scaled, cv.COLOR_BGR2RGB)) ax[0].set_title("Linear Interpolation Scale")   image_scaled_2 = cv.resize(image,
        None, fx=2, fy=ii, interpolation=cv.INTER_CUBIC) ax[1].imshow(cv.cvtColor(image_scaled_2, cv.COLOR_BGR2RGB)) ax[1].set_title("Cubic Interpolation Scale")   image_scaled_3 = cv.resize(image, (200,
        400), interpolation=cv.INTER_AREA) ax[2].imshow(cv.cvtColor(image_scaled_3, cv.COLOR_BGR2RGB)) ax[two].set_title("Skewed Interpolation Scale")
      
scaling and resizing image

Scaling of an paradigm refers to converting an image assortment into lower or higher dimensions.

These are some of the most basic operations that tin be performed with the OpenCV on an epitome. Autonomously from this, OpenCV can perform operations such as
Image Segmentation, Face Detection, Object Detection, 3-D reconstruction, feature extraction
also.

If you want to have a look at how these pictures were generated using
OpenCV
then you can cheque out this GitHub
repository.

2. Scikit-Paradigm

scikit-paradigm
is a python-based image processing library that has some parts written in
Cython
(Cython is a programming language which is a superset of Python programming language designed to have functioning like C programming linguistic communication.) to achieve practiced performance. Information technology includes algorithms for:

  • Segmentation,
  • Geometric transformations,
  • Color space manipulation,
  • Analysis,
  • Filtering,
  • Morphology,
  • Feature detection, and more

Y’all will find it useful for pretty much any
computer vision
task.

The scikit-image
uses
NumPy
arrays as image objects.

Operation using

scikit-image

Active contour

active contour

In calculator vision, profile models describe the boundaries of shapes in an image.

“Active contour models are defined for image segmentation based on the curve menstruum, curvature, and profile to obtain the exact target region or segment in the image.”

Following lawmaking produces the to a higher place output:

        import
        numpy
        as
        np
        import
        matplotlib.pyplot
        as
        plt
        from
        skimage.color
        import
        rgb2gray
        from
        skimage
        import
        data
        from
        skimage.filters
        import
        gaussian
        from
        skimage.partitioning
        import
        active_contour  img = data.astronaut()    s = np.linspace(0,
        2*np.pi,
        400) x =
        220
        +
        100*np.cos(southward) y =
        100
        +
        100*np.sin(s) init = np.array([x, y]).T   cntr = active_contour(gaussian(img,
        3),init, alpha=0.015, beta=10, gamma=0.001) fig, ax = plt.subplots(one,
        two, figsize=(7,
        7)) ax[0].imshow(img, cmap=plt.cm.gray) ax[0].set_title("Original Image")  ax[1].imshow(img, cmap=plt.cm.gray)  ax[1].plot(init[:,
        0], init[:,
        1],
        '--r', lw=3) ax[1].plot(cntr[:,
        0], cntr[:,
        one],
        '-b', lw=3) ax[i].set_title("Active Contour Epitome")
      

three. SciPy

Scipy
is used for mathematical and scientific computations merely can also perform multi-dimensional prototype processing using the submodule
scipy.ndimage. It provides functions to operate on north-dimensional Numpy arrays and at the terminate of the mean solar day images are simply that.

Scipy
offers the most commonly used image processing operations like:

  • Reading Images
  • Epitome Segmentation
  • Convolution
  • Face Detection
  • Feature Extraction and then on.

Blurring an image with

scipy

        from
        scipy
        import
        misc,ndimage
        from
        matplotlib
        import
        pyplot
        equally
        plt  face = misc.face() blurred_face = ndimage.gaussian_filter(face, sigma=3)  fig, ax = plt.subplots(i,
        2, figsize=(16,
        8))  ax[0].imshow(face up) ax[0].set_title("Original Image") ax[0].set_xticks([]) ax[0].set_yticks([])   ax[ane].imshow(blurred_face) ax[ane].set_title("Blurred Image") ax[one].set_xticks([]) ax[1].set_yticks([])

Output:

blurring image effect

You tin detect all operations
hither.

4. Pillow/PIL

PIL logo

PIL (Python Imaging Library)
is an open-source library for image processing tasks that requires python programming language.
PIL
can perform tasks on an image such as reading, rescaling, saving in different paradigm formats.

PIL
can be used for Image archives, Image processing, Paradigm display.

Image enhancement with PIL

For example, let’s enhance the post-obit image by 30% contrast.

cat

        from
        PIL
        import
        Image, ImageFilter  im = Epitome.open('cat_inpainted.png')  im.prove()
        from
        PIL
        import
        ImageEnhance enh = ImageEnhance.Contrast(im) enh.enhance(1.8).show("xxx% more contrast")

Output:

cat enhanced

For more than data go here.

5. NumPy

numpy logo

An epitome is essentially an array of pixel values where each pixel is represented past i (greyscale) or 3 (RGB) values. Therefore, NumPy tin can easily perform tasks such equally image cropping, masking, or manipulation of pixel values.

For case to excerpt red/green/bluish channels from the following image:

color extract

We tin utilize numpy and “penalize” each channel one at a time by replacing all the pixel values with zero.

        from
        PIL
        import
        Image
        import
        numpy
        every bit
        np  im = np.array(Paradigm.open('goku.png'))  im_R = im.copy() im_R[:, :, (1,
        two)] =
        0
        im_G = im.re-create() im_G[:, :, (0,
        2)] =
        0
        im_B = im.copy() im_B[:, :, (0,
        1)] =
        0
        im_RGB = np.concatenate((im_R, im_G, im_B), axis=1)  pil_img = Epitome.fromarray(im_RGB) pil_img.salve('goku.jpg')
colors extracted effect

vi. Mahotas

Mahotas
is another image processing and computer vision library that was designed for
bioimage information science. It reads and writes images in NumPy array, and is implemented in C++ with a smooth python interface.

The near popular functions of Mahotas are

  • Watershed
  • Convex points calculations
  • hitting & miss. Thinning
  • Morphological Processing
  • Template Matching.

Let’south meet how Template Matching can be done with
Mahotas

for
finding the wally.

The post-obit lawmaking snippet helps in finding the Wally in the crowd.

        from
        pylab
        import
        imshow, evidence
        import
        mahotas
        import
        mahotas.demos
        import
        numpy
        as
        np  wally = mahotas.demos.load('Wally') wfloat = wally.astype(float)  r,g,b = wfloat.transpose((two,0,1)) w = wfloat.mean(ii) pattern = np.ones((24,16), float)
        for
        i
        in
        range(2):     design[i::4] =
        -i
        5 = mahotas.convolve(r-westward, design)     mask = (v == v.max())     mask = mahotas.dilate(mask, np.ones((48,24)))     np.subtract(wally,
        .8*wally * ~mask[:,:,None], out=wally, casting='unsafe') imshow(wally) show()


7. SimpleITK

ITK or
Insight Segmentation and Registration Toolkit
is an open-source platform that is widely used for Image Partitioning and Image Registration (a procedure that overlays two or more images).

Image partition

ITK uses the
CMake

build environment and the library is implemented in C++ which is wrapped for Python.

registration visualization

You tin check this Jupyter Notebook for learning and inquiry purposes.

eight. Pgmagick

Pgmagick is a
GraphicsMagick

binding for Python that provides utilities to perform on images such equally resizing, rotation, sharpening, gradient images, drawing text, etc.

Blurring an epitome

        from
        pgmagick.api
        import
        Image   img = Epitome('leena.jpeg')    img.blur(ten,
        5)
blurring images

blurred image

Scaling of an paradigm

        from
        pgmagick.api
        import
        Image     img = Image('leena.png')      img.scale((150,
        100),
        'leena_scaled')
      
scaling image

scaling image

For more info, y’all tin can bank check the curated list of Jupyter Notebooks here.

Final thoughts

We have covered the top 8 image processing libraries for machine learning. Hopefully, you now accept an thought of which ane of those will piece of work best for your project. Best of luck. 🙂

Python & Motorcar Learning Teacher | Founder of probog.com


READ NEXT

ML Experiment Tracking: What It Is, Why Information technology Matters, and How to Implement It

10 mins read | Writer Jakub Czakon | Updated July 14th, 2021

Let me share a story that I’ve heard too many times.

”… Nosotros were developing an ML model with my team, we ran a lot of experiments and got promising results…

…unfortunately, we couldn’t tell exactly what performed best because we forgot to salve some model parameters and dataset versions…

…after a few weeks, we weren’t even sure what we have actually tried and we needed to re-run pretty much everything”

– unfortunate ML researcher.

And the truth is, when you develop ML models y’all will run a lot of experiments.

Those experiments may:

  • utilize unlike models and model hyperparameters
  • apply different grooming or evaluation data,
  • run different code (including this pocket-size change that y’all wanted to exam quickly)
  • run the same code in a different environment (not knowing which PyTorch or Tensorflow version was installed)

And as a event, they tin produce completely unlike evaluation metrics.

Keeping track of all that information can very quickly get actually hard. Especially if you desire to organize and compare those experiments and feel confident that yous know which setup produced the best consequence.

This is where ML experiment tracking comes in.

Continue reading ->


Source: https://neptune.ai/blog/image-processing-python-libraries-for-machine-learning