Image segmentation using GNU Octave

With PMA.start, it is very easy to load whole slide images in GNU Octave and run image analysis algorithms.

To work with images, we first need to install the ‘image’ package from forge by issuing:

pkg install -forge image

In order to interact with the web API of PMA.start, we need a JSON parser for Octave. An easy to use one can be found here Extract it locally and load it in Octave by issuing:


Now we are ready to do some image analysis:

% define the path to a WSI. You can download a sample WSI here

% build the image info URL
infoUrl=['http://localhost:54001/api/json/GetImageInfo?pathOrUid=' imagePath];

% fetch image info as JSON

% parse it

% calculate a scale factor that produces an image at most 1500 pixels wide or tall, but don't scale up the image
scale=min(1500 / (max(imInfo.d.Width, imInfo.d.Height)), 1)

% download the image from PMA.start
imgUrl=['http://localhost:54001/region?pathOrUid=' imagePath '&width=' num2str(imInfo.d.Width) '&height=' num2str(imInfo.d.Height) '&x=0&y=0&scale=' num2str(scale) '&timeframe=0&layer=0';];

% read it
figure,imshow(wsi); title('WSI');

% convert the image to grayscale
figure,imshow(gray); title('Grayscale');

% blur it - the actual blur factor depends on the type of the image
blur=imsmooth(gray, 'Gaussian', 5);
figure,imshow(blur); title('Blur');

% run Otsu threshold

% convert the image to black and white
bw=im2bw(blur, th);
figure,imshow(bw); title('Black - white');

% run edge detection - multiple methods are available
edges=edge(mat2gray(bw), 'Canny');
figure,imshow(edges); title('Edges');

Input image



Click here to download here the complete Octave example.