CLIJ2

Logo

GPU accelerated image processing for everyone

CLIJ2 home

Crop and paste images

Authors: Robert Haase, Daniela Vorkel, April 2020

Source

This macro shows how to crop and paste images in the GPU.

// clean up first
run("Close All");

// get test data
run("Blobs (25K)");
run("Invert LUT");
input = getTitle();

blobs.gif

Initialize GPU and push image to GPU memory

run("CLIJ2 Macro Extensions", "cl_device=");
Ext.CLIJ2_clear();

// push images to GPU
Ext.CLIJ2_push(input);

Crop out a part of the image

We now crop out a part of the image and show its result:

x = 10;
y = 10;
width = 75;
height = 75;
Ext.CLIJ2_crop2D(input, cropped, x, y, width, height);

// show result
Ext.CLIJ2_pull(cropped);

CLIJ2_crop2D_result12

Paste one image into another image

We create an empty image and make a collage by pasting the cropped image into it. We also transform the cropped image for visualisation purpose:


bit_depth = 8;
Ext.CLIJ2_create2D(collage, width * 2 + 6, height * 2 + 6, bit_depth);

// fill the background of the collage with white pixels
Ext.CLIJ2_set(collage, 255);

// flip and paste tiles
Ext.CLIJ2_paste2D(cropped, collage, 2, 2);

Ext.CLIJ2_flip2D(cropped, flipped, true, false);
Ext.CLIJ2_paste2D(flipped, collage, width + 4, 2);

Ext.CLIJ2_flip2D(cropped, flipped, true, true);
Ext.CLIJ2_paste2D(flipped, collage, width + 4, height + 4);

Ext.CLIJ2_flip2D(cropped, flipped, false, true);
Ext.CLIJ2_paste2D(flipped, collage, 2, height + 4);

// show collage
Ext.CLIJ2_pull(collage);

CLIJ2_create2D_result13

At the end of the macro, clean up:

Ext.CLIJ2_clear();