gjheij / linescanning

Package for (pre)processing of anatomical and (linescanning) fMRI data
MIT License
12 stars 3 forks source link

Vertex2D_fix -> help with additional colormaps #20

Open mdaghlian opened 8 months ago

mdaghlian commented 8 months ago

pycortex.py from line 923

Original

# Map to RGB
self.vx_rgb = np.vstack([self.vx.raw.red.data, self.vx.raw.green.data, self.vx.raw.blue.data])

# Pick an arbitrary region to mask out
# (in your case you could use np.isnan on your data in similar fashion)
self.alpha = np.clip(self.norm2(self.data2), 0, 1).astype(float)

# Map to RGB
self.vx_rgb[:,self.alpha>0] = self.vx_rgb[:,self.alpha>0] * self.alpha[self.alpha>0]

self.curv_rgb = np.vstack([self.curv.raw.red.data, self.curv.raw.green.data, self.curv.raw.blue.data])

# do this to avoid artifacts where curvature gets color of 0 valur of colormap
self.curv_rgb[:,np.where((self.vx_rgb > 0))[-1]] = self.curv_rgb[:,np.where((self.vx_rgb > 0))[-1]] * (1-self.alpha)[np.where((self.vx_rgb > 0))[-1]]

# Alpha mask
self.display_data = self.curv_rgb + self.vx_rgb 

# display_data = curv_rgb * (1-alpha) + vx_rgb * alpha

Easy fix:

# Map to RGB
self.vx_rgb = np.vstack([self.vx.raw.red.data, self.vx.raw.green.data, self.vx.raw.blue.data])

# Pick an arbitrary region to mask out
# (in your case you could use np.isnan on your data in similar fashion)
self.alpha = np.clip(self.norm2(self.data2), 0, 1).astype(float)

# Map to RGB
self.curv_rgb = np.vstack([self.curv.raw.red.data, self.curv.raw.green.data, self.curv.raw.blue.data])

self.display_data = curv_rgb * (1-self.alpha) + vx_rgb * self.alpha

# Force uint8, otherwise it gets upset
self.display_data = self.display_data.astype(np.uint8)

Run a test using the 'plasma' colormap. It should be dodgy using the old version, but fixed with the new one.