Skip to content

Commit

Permalink
Fixed CZI RGB and BGR confusion and thumbnail image.
Browse files Browse the repository at this point in the history
  • Loading branch information
maubreville committed Jan 15, 2025
1 parent 8e550b2 commit 635fc09
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions exact/util/slideio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def __init__(self,filename):
self.levels = [1]
self.mpp_x = self.scene.resolution[0]*1e6
self.mpp_y = self.scene.resolution[1]*1e6
self.mode = 'RGBA' # normally, it is RGB not BGR

# Zeiss is funny and thinks BGR is the proper way to store images ...
if (os.path.splitext(filename.upper())[-1] == '.CZI'):
self.mode = 'BGRA'


#print('Circular mask shape:',self.circMask.shape)
self.properties = { openslide.PROPERTY_NAME_BACKGROUND_COLOR: '000000',
Expand Down Expand Up @@ -89,15 +95,15 @@ def frame_type(self):


def get_thumbnail(self, size):
return Image.fromarray(self.scene.read_block(rect=self.scene.rect, size=size))
return Image.fromarray(self.scene.read_block(rect=[0, 0, *self.scene.rect[2:]], size=size))


def read_region(self, location: tuple, level:int, size:tuple, frame:int=0):
ds = self.scene.get_zoom_level_info(level).scale
img = self.scene.read_block(rect=[*location, int(size[0]/ds), int(size[1]/ds)], size=size)
img_4ch = np.zeros([size[1], size[0],4], dtype=np.uint8)
img_4ch[:,:,3] = 255
img_4ch[:,:,0:3] = img
img_4ch[:,:,0:3] = img if self.mode=='RGBA' else img[:,:,::-1]
return Image.fromarray(img_4ch)

@property
Expand Down

0 comments on commit 635fc09

Please sign in to comment.