probably there is quite an easy solution (without looping around), I am searching for the fastest way possible to:
Set all channels of an rgb image in a stack of images of shape (10, 2160, 4096, 3) to nan if a value in one channel of a stack of mask images of the same shape exceeds a certain threshold t.
for i in range(np.shape(stack)[0]):
stack[mask[i,:,:,:] > t] = np.nan
This obviously does no do the job yet as it would only set the values in the same channel to nan. Any help on how to do this? And how to do it as fast as possible (maybe I do not even have to loop over the images in the stack?) Thanks and cheers!
答案 0 :(得分:0)
因此,对于任何绊倒这个的人,我的解决方案最终是:
stack[np.nansum(mask > t, axis=-1)>0 ,:] = np.nan
(掩码> t,轴= -1)给出了一个大小为3的二进制数组,具体取决于条件,然后我总结一下,如果只有一个值高于1(高于阈值),则> ; 0也完成了。我再次添加了通道尺寸,并让我的条件数组我评估为“堆栈”。
我还需要具有三个不同阈值以及所有三个通道的上限和下限的内容,为了完成,我将在此处添加:
th1=[tl1,tl2,tl3]
th2=[tu1,tu2,tu3]
stack[((mask < th2).any(axis=-1) | (mask > th1).any(axis=-1)), :] = np.nan
干杯!