Documentation‎ > ‎

3. Filter

1. Load an image from bitmap file and apply canny edge filtering

    Image:io handle all image file parsing. By using << and >> operator, the image parser copy the data to the image data.


#include "tipl/tipl.hpp"
#include <iostream>

int main()
{
    tipl::grayscale_image image_data,label_data;
    tipl::io::bitmap bitmap_file;
    tipl::io::nifti nifti_file;

    if(!bitmap_file.load_from_file("canny_edge_test.bmp"))
    {
        std::cout << "cannot read canny_edge_test.bmp" << std::endl;
        return;
    }
    bitmap_file >> image_data;

    tipl::filter::gaussian(image_data);
    tipl::filter::gaussian(image_data);
    tipl::filter::gaussian(image_data);
    tipl::filter::canny_edge(image_data);

    nifti_file << image_data;
    nifti_file.save_to_file("result_canny_edge.nii");
    return 0;
}

2. Load an image and apply anisotropic diffusion filter

#include "tipl/tipl.hpp"
int main()
{
    tipl::io::bitmap reader;
    if(!reader.load_from_file("images/input_bmp.bmp"))
        return 0;
    tipl::grayscale_image I;
    reader >> I;
    // note that the anisotropic diffusion require a wider dynamic range.
    tipl::image<int,2> I2(I);
    tipl::filter::anisotropic_diffusion(I2);

    tipl::grayscale_image out(I2);
    reader << out;
    reader.save_to_file("images/result_anisotropic.bmp");
}
 

    Note that the syntax in the following example can be applied to both 2D or 3D images.

Mean filter

    Smooth the image using (1,1,1; 1,1,1; 1,1,1) kernel.

tipl::filter::mean(image_data);

Gaussian filter

tipl::filter::gaussian(image_data);

Laplacian filter

tipl::filter::laplacian(image_data);

Sobel filter

    An edge magnitude filter. The result is the abs(gx) + abs(gy) in 2D image.

tipl::filter::sobel(image_data);

Canny Edge Detector




#include "tipl/tipl.hpp"
#include <iostream>


int main()
{
    // canny edge detector
    tipl::grayscale_image image_data,label_data;
    tipl::io::bitmap bitmap_file,out_file;

    if(!bitmap_file.load_from_file("canny_edge_test.bmp"))
    {
        std::cout << "cannot read canny_edge_test.bmp" << std::endl;
        return 0;
    }
    bitmap_file >> image_data;

    tipl::filter::gaussian(image_data);
    tipl::filter::gaussian(image_data);
    tipl::filter::gaussian(image_data);
    tipl::filter::canny_edge(image_data);

    out_file << image_data;
    out_file.save_to_file("result_canny_edge.bmp");
    return 0;
}


Anisotropic diffusion filter

    Edge preserving smoothing.

tipl::filter::anisotropic_diffusion(image_data);

Comments