Open lauramurgatroyd opened 10 months ago
I will also be checking the behaviour of the axis parameter with the other masking options: median and interpolate, and update on this here.
Same result with median:
Opposite result with 'interpolate' - this one behaves as I expected!
Note, when investigating I also encountered this issue https://github.com/TomographicImaging/CIL/issues/1531, which is why I had to edit to update one of the images posted above (so it did not include the effects of this additional problem)
Code to reproduce the above:
#%%
import numpy as np
from cil.utilities.display import show2D
from cil.processors import Masker
from cil.framework import DataContainer
from cil.framework import ImageGeometry, DataContainer
import logging
logging.basicConfig(level=logging.WARNING)
cil_log_level = logging.getLogger('cil.processors')
cil_log_level.setLevel(logging.DEBUG)
#%%
example_data = DataContainer(np.array([[0.1,0.1,0.1], [0.3,0.3,0.3], [0.2,0.2,0.2]]))
example_mask = DataContainer(np.array([[True,True,True], [True,False,True], [True,True,True]]))
example_data.dimension_labels = ['vertical', 'horizontal']
example_mask.dimension_labels = ['vertical', 'horizontal']
show2D([example_data, example_mask], title= ["Data", "Mask"])
#%%
mean_horiz_mask = Masker(mask=example_mask, mode='mean', axis='horizontal')
mean_vert_mask = Masker(mask=example_mask, mode='mean', axis='vertical')
masked_horiz = mean_horiz_mask(example_data)
masked_vert = mean_vert_mask(example_data)
show2D([masked_horiz, masked_vert], title=['Horizontal Mean', 'Vertical Mean'])
#%%
median_vert = Masker(mask=example_mask, mode='median', axis='vertical')(example_data)
median_horiz = Masker(mask=example_mask, mode='median', axis='horizontal')(example_data)
show2D([median_horiz, median_vert], title=['Horizontal Median', 'Vertical Median'])
#%%
interp_vert = Masker(mask=example_mask, mode='interpolate', axis='vertical')(example_data)
interp_horiz = Masker(mask=example_mask, mode='interpolate', axis='horizontal')(example_data)
show2D([interp_horiz, interp_vert], title=['Horizontal Interp', 'Vertical Interp'])
In the documentation for Masker, the mean method takes a parameter 'axis', and it "sets the masked values of the input data to the mean of the unmasked values across the [..] axis." I tested this out and got the following results (labelled 'Horizontal Mean' means I set axis='horizontal').
The behaviour was opposite to what I expected. I expected setting 'horizontal' to mean averaging across the rest of the pixels in the horizontal direction...
[Note: edited to update this image]![image](https://github.com/TomographicImaging/CIL/assets/60604372/8721923b-e6b2-488d-92a0-b7f5c55dca64)