Getting Started with ImageProcessing

Preparing


Requirements

First of all, make sure the following requirements are installed on your system:

To find more building and running options take a look at the MiniScaffold template.

Package Adding

Go to directory with your build.fsproj (or build.csproj) file and install ImageProcessing using command line:

dotnet add package ImageProcessing.PolinaSavelyeva --version 1.0.0

For more information visit package main GitHub page.

Features


The following features are implemented, even for CPU and GPU:

For detailed descriptions of all features above visit Api Reference.

Simple Usage


Using CLI

Before usage, go to specify directory:

cd /path/to/ImageProcessing/src/ImageProcessing

To process images from one directory and save them to another, you can use the following commands.

dotnet run -in /input/path -out /output/path -agent=full -unit=cpu gauss
dotnet run -in /input/path -out /output/path  -agent=no -unit=anygpu gauss sharpen

You can find more details about CLI processing here.

Using Your Own Code

Open library and load image to process:

open MyImage
open CPU
open GPU

let myImage = load ("Full/Path/To/Images/Folder/image_name.jpg")

Create new function which sequentially applies blur filter and clockwise rotation to images and saves it on CPU:

let applyCustomFilterOnCPU (image: MyImage) (pathToSave : string) = 
    let blurredImage = image |> applyFilter gaussianBlurKernel
    let rotatedImage = blurredImage |> rotate true
    
    MyImage.save rotatedImage pathToSave

Create the same function for GPU. But before it we need to do some steps for diagnosing graphical device.

Define the device value by specifying the brand of your GPU or whatever the program finds (embedded graphics cards are also suitable). And make OpenCL context of it:

let device = Brahma.FSharp.ClDevice.GetFirstAppropriateDevice()
let clContext = Brahma.FSharp.ClContext(device)

Next, define new values for filter and rotation functions. This action is necessary because of compiling kernel function once:

let applyFilterGPU = applyFilter clContext 64
let rotateGPU = rotate clContext 64

And the final function:

let applyCustomFilterOnGPU (image: MyImage) (pathToSave : string) = 
    let blurredImage = image |> applyFilterGPU gaussianBlurKernel
    let rotatedImage = blurredImage |> rotateGPU true
    
    MyImage.save rotatedImage pathToSave

The result:

open MyImage
open CPU
open GPU

let myImage = load ("Full/Path/To/Images/Folder/image_name.jpg")

let applyCustomFilterOnCPU (image: MyImage) (pathToSave : string) = 
    let blurredImage = image |> applyFilter gaussianBlurKernel
    let rotatedImage = blurredImage |> rotate true
    
    MyImage.save rotatedImage pathToSave

let device = Brahma.FSharp.ClDevice.GetFirstAppropriateDevice()
let clContext = Brahma.FSharp.ClContext(device)

let applyFilterGPU = applyFilter clContext 64
let rotateGPU = rotate clContext 64

let applyCustomFilterOnGPU (image: MyImage) (pathToSave : string) = 
    let blurredImage = image |> applyFilterGPU gaussianBlurKernel
    let rotatedImage = blurredImage |> rotateGPU true
    
    MyImage.save rotatedImage pathToSave
 
let pathToSave = "Path/To/Directory/image_name.jpg"

applyCustomFilterOnCPU myImage pathToSave
applyCustomFilterOnGPU myImage pathToSave
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String