IMSY-DKFZ / simpa

The Simulation and Image Processing for Photonics and Acoustics (SIMPA) toolkit.
https://simpa.readthedocs.io/en/main/
Other
70 stars 17 forks source link

Possible Bug: Rot90 in kwave adapter #264

Closed faberno closed 2 months ago

faberno commented 6 months ago

Describe the bug The kwave adapter uses rot90 to orient the images/volumes for the kwave axis convention. But rot90 does not preserve the original positions in the image. This is because np.arrays origin is the top-left corner and rot90 maps this corner to top-right, instead preserving it at the top left.

Here an example based optical_and_acoustic_simulation.py, where the sensor position and vessel position are set to VOLUME_TRANSDUCER_DIM_IN_MM/3 (not in the middle as before): bug In the original slice the vessel sits at index 125. After rot90 it sits at index 250. Intead transpose would be the correct behaviour.

By looking the p0 map and the sensor in kwave we can see that this unaligns sensor and the properties: p0_sensor

Specify a priority (low, medium, high) high

To Reproduce

-> optical_and_acoustic_simulation.py

Additional context Solution: -> acoustic_forward_module_k_wave_adapter.py

data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND][image_slice].T data_dict[Tags.DATA_FIELD_DENSITY] = data_dict[Tags.DATA_FIELD_DENSITY][image_slice].T data_dict[Tags.DATA_FIELD_ALPHA_COEFF] = data_dict[Tags.DATA_FIELD_ALPHA_COEFF][image_slice].T data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE] = data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE][image_slice].T

TomTomRixRix commented 5 months ago

Nice find :+1: I could reproduce the bug and see the mismatching orientation when looking at the .mat file. I assume we haven't found this bug yet because we always placed the probe centrally so that it works symmetrically. But maybe this caused some off-by-one errors.

In addition to using transpose instead of rot90 we would also have to remove this line in order to obtain a correctly flipped time series data, because now the sensor elements are correctly ordered

# reverse the order of detector elements from matlab to python order
raw_time_series_data = raw_time_series_data[::-1, :]

bug