smistad / FAST

A framework for high-performance medical image processing, neural network inference and visualization
https://fast.eriksmistad.no
BSD 2-Clause "Simplified" License
433 stars 101 forks source link

Automatic ultrasound sector cropping #196

Closed quancore closed 9 months ago

quancore commented 9 months ago

I am trying to crop GUI elements from single ultrasound images but it does not work (tried different thresholds), what should I do for this case?

importer = fast.ImageFileImporter.create(str(image_file))
cropper = fast.UltrasoundImageCropper.New().create(
    staticCropping=False, # Estimate cropping on first frame only or not
    thresholdVertical=50,
    thresholdHorizontal=10,
).connect(importer)
renderer = fast.ImageRenderer.create()\
    .connect(importer)

renderer2 = fast.ImageRenderer.create()\
    .connect(cropper)

fast.DualViewWindow2D.create()\
    .connectLeft(renderer)\
    .connectRight(renderer2)\
    .run()

image

smistad commented 9 months ago

The UltrasoundImageCropper is far from perfect. Especially for sector scans. It can be hard to find a threshold that works perfectly for all cases. Still, looking at your input image, in this particular case, it should work with the right threshold values.

quancore commented 9 months ago

One of the problems is that there is no proper explanation about those threshold values and how to setup for different cases, maybe you can elaborate a bit?

smistad commented 9 months ago

For each column and each row it counts how many pixels have a value above 0. To find the min x and max x positions, it starts from the middle and stops at the first x position which has a number of pixels equal to 0 above the thresholdHorizontal. It does this both in the left and right direction. Then this is repeated for the vertical direction, y using thresholdVertical.

smistad commented 9 months ago

I have added more documentation on this method. Thanks. Closing.