Skip to content

DIPlib 3.0

Introduction

Since 2020 a new implementation of DIPlib is available with version 3.0. Below is a small instruction on how to install DIPlib in Windows 10 and how to use the Python binding. All documentation about DIPlib and the API can be found on this site:

Install

For this installation we will use Python version 3.7 and not use Matlab.

DIPlib

Install DIPlib by downloading the beta-release from here:

Execute the installer and accept the default settings.

Visual C++ Redistributable for Visual Studio 2019

To use DIPlib you will need to install Visual C++ Redistributable for Visual Studio 2019. Download from here:

Execute the installer and accept the default settings.

Python (with Miniconda)

To setup Miniconda follow the instructions in Miniconda.

Then open the Anaconda Powershell Prompt (miniconda) and enter the following commands:

# for diplib 3.0 beta you need python 3.7, matplotlib,
#   jupyter and opencv (cv2)
> conda create -n diplib python=3.7 matplotlib jupyter libopencv opencv py-opencv
> conda activate diplib
# tell python were to find the diplib python package PyDIP
> $env:pythonpath = 'C:\Program Files\DIPlib 3\lib\'

Example using DIPlib in Python

Below is an example on how to use DIPlib in Python. This example uses the example in OpenCV in Python to read in a movie (e.g. from your smartphone) and convert this to a smaller movie with only gray-values. Afterwards the result is converted to a dipImage object and stored and read with the dip.Image-write and -read functions.

import PyDIP as dip
import PyDIP.PyDIPviewer as dv

import cv2
import numpy as np

cap = cv2.VideoCapture('IMG_5915.MOV')
if (cap.isOpened()== False):
    print("Error opening video stream or file")

minSize = 512

width  = cap.get(cv2.CAP_PROP_FRAME_WIDTH)   # float
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)  # float
scale = minSize / min(width, height)
scaleWidth = int(scale * width)
scaleHeight = int(scale * height)
dim = (scaleWidth, scaleHeight)

rawMovie = []
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        small = cv2.resize(frame, dim)
        gray = cv2.cvtColor(small, cv2.COLOR_BGR2GRAY)
        rawMove.append(gray)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break
    else:
        break
cap.release()

dipMovie = dip.Image(np.array(rawMovie))

dip.ImageWriteICS(dipMovie, 'IMG_5915.ics')

dipMovie = dip.ImageReadICS('IMG_5915.ics')

Happy DIPing!


Last update: 2021-02-20