Page MenuHomePhabricator

Boolean Operations in Segmentation utilities are slow
Open, NormalPublic

Description

open both files in MITK, open segmentation utilities (not multilabel!)

Then run difference, union or intersection.

Due to the large image size all of these take a long time:
Difference: ~14s
Intersection: ~13.5s
Union: ~12s
(times measured with a stop watch, so +- 0.5s)

I understand that there is some overhead involved with writing back the result into some image and then displaying it, but boolean operations are rather basic stuff and should run WAY faster.

Furthermore MITK uses a an unreasonable amount of RAM to compute the results (compared to a python implementation). That is probably because the target image is unsigned short, even though both source images were unsigned char. Why?

Here is a reference implementation in python:

import numpy as np
import tifffile
from time import time

a = tifffile.imread('tmp2.tif')
b = tifffile.imread('tmp3.tif')

# difference
st = time()
c = np.copy(a)
c[b > 0] = 0
end = time()
print('difference took', end - st, 's')

# union
st = time()
c = ((a > 0) | (b > 0)).astype(np.uint8)
end = time()
print('union took', end - st, 's')

# intersection
st = time()
c = ((a > 0) & (b > 0)).astype(np.uint8)
end = time()
print('intersection took', end - st, 's')

difference took 0.4352085590362549 s
union took 0.5148181915283203 s
intersection took 0.5096790790557861 s

Even though MITK uses multiprocessing the single threaded python/numpy implementation is much faster.

Best,

Fabian

Event Timeline

isensee renamed this task from Boolean Operations in Segmentation utilities are excruciatingly slow to Boolean Operations in Segmentation utilities are slow.Aug 24 2021, 10:31 AM
kislinsk triaged this task as Normal priority.Wed, Sep 15, 4:54 AM
kislinsk edited projects, added MITK (v2021.10); removed MITK.
kislinsk added a subscriber: kislinsk.

This could be connected to the undo/redo implementation of MITK and the creation of difference images for the undo stack. I do not know your version of MITK but the use of LZ4 compression for difference images in the latest versions could already be the or part of the solution. I agree that the operations should be much faster but they might be already as fast as the python implementation so whoever is working on this task should clock the different parts of the operation first to see what is actually taking so long and as said, if it is still the case in the latest version of MITK.