Computer Vision News - December 2022
33 Visualizing Data with Mayavi Extra Since we previously mentioned the importance of the TVTK module, below we report an example of how to use filters to threshold and segment an image. This is an example reproduced from the Mayavi documentation on a brain scan. You can use this code, apply it on your image and personalise it with suitable values for the thresholding. from tvtk.api import tvtk # Apply image-based filters to clean up noise thresh_filter = tvtk.ImageThreshold() thresh_filter.threshold_between(lower_thr, upper_thr) thresh = mlab.pipeline.user_defined(src, filter=thresh_filter) median_filter = tvtk.ImageMedian3D() median_filter.set_kernel_size(3, 3, 3) median = mlab.pipeline.user_defined(thresh, filter=median_filter) diffuse_filter = tvtk.ImageAnisotropicDiffusion3D( diffusion_factor=1.0, diffusion_threshold=100.0, number_of_iterations=5, ) diffuse = mlab.pipeline.user_defined(median, filter=diffuse_filter) # Extract brain surface contour = mlab.pipeline.contour(diffuse, ) contour.filter.contours = [brain_thr, ] This was a very short overview of Mayavi, but we won’t stop here and there is plenty of other visualization toolkits for Python to explore. Keep following us for more in 2023!
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=