OpenCV Function exploring and Image Stabilisation for DICOM

The open CV library www.opencv.org provides many useful functions for image processing. But it can be difficult and slow to learn the best parameter values and the optimum order to apply them. My first application of opencv was to count the flock sizes of birds and I wanted to optimise the operations for enhancing the image prior to applying the counting mechanism.

For the next project I wanted to be able to experiment “interactively” with the order of the processes and also to convert grayscale images to a 3D representation. (the project was to find an slightly embossed area on a rusty sign on a canal aqueduct).

So I wrote apython application to facilitate this and a version of it is shown below.

( For anyone wanting to learn about opencv an excellent resource is https://www.pyimagesearch.com/ )

The ‘pipeline’ of processes is shown on the left and their order can be changed and they can be enabled or disabled via the checkbox. The process panel (in blue above) shows the image being input to a processing stage and the output from that stage. The large image shows the result after the image has been processed by all the enabled stages of the pipeline. The 3d image shows the grayscale values converted to heights.

I also wanted a testing environment for future android projects and so decided to try a java implementation. The current version is shown below and its operation is the same as the python version shown above.

The UI of the JAVA version showing effect of canny edge detection

The next addition was to use template matching to provide image stabilization of a series of jpeg images in which an object was not always in the same location in the photo but for comparison purpose needed to be overlaid.

Image Stabilisation

The image processing pipeline is use to improve contrast of the image. A section of the enhanced image is then used as a template which is is searched for in each image of the image set. The co-ordinates of the located item are then used to extract the selection from the ORIGINAL image set and saved as a new file.The enhanced images and template are only used to locate the region of interest.

Medical Application DICOM Image stabilisation

Many medical imaging modalities save their resultant images as a sequence of images in the DICOM format.

In some image sequence the item of interest moves due to movement of the patient or their organs for example due to breathing. The work-around can be for each image to be examined and processed manual to select and crop the item of interest. This is time consuming as such images may be a set of hundred of images.

To assist some medical colleagues I modified the code to process dicom series. The specific scenario here is wanting to identify and extract the kidney in the sequence shown. This was to enable co-registration of the images for use by another diagnostic tool.

The constrained matcher shows the selected reference template (in a green rectangle). The output of the filter shows a white rectangle around the matched area in the test image, the large image on the right shows a zoom view.

The filter can either show the matched region (show in first section of the video) or as the extracted rectangle on its its own (as shown later in the video).

The matching method can also be changed via the dropdown in the filter.

To “help” the matcher a “contraint area” has been selected (the blue rectangle) and this limits where in the input image the matcher is limited to searching. There are other subtleties involved in this process such as selecting which “slice” of an image has the best shape to use as a template and means of filtering the relevant dicom positions.

The next version really needs some deep learning enhancement 🙂

Example of stabilising image

A download of the application will be available in future.

This entry was posted in android, coding, computing, dicom, imaging, JAVA, matplotlib, opencv, pandas, python, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply