Problems using czi image container

Your place to discuss general handling of images and the CZI file format
Post Reply
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Problems using czi image container

Post by user-6033 »

Hi,

Unfortunately I need to verify a few things regarding saving a collection of files into one single ZenImage container file. We have avoided this scheme so far since we found there were some issues with image format but since there is large times saving to gain when image number is counted in hundreds I have made some testing once more and maybe this is something for you to have a look on since there still seems to be unexpected results.

We use Zen Core 2.7 h2. The source file is 14 bit in B/W mode acquired by an Axiocam 506 Color. Single files are saved as Gray16 without any problems as far as I can tell. We want to keep the pixel format as Gray16. We have pre-allocated the ZenImage as either Gray16 or as Bgr48, or had it as an empty default container. The images have been added as subimages using Z as index and later on retrieved as created images where z-index also is used. The Zen.Windows.ShowImage2d is used as the image viewer and we have tried some segmentation on images (interactive) and used preview on those.

With images = ZenImage() the result is as expected when viewing the retrieved image and the pipette tool also confirms pixel range 0 – 16384. However, metadata tells us that the pixeltype is Gray8, which may cause problems for function relying on correct action for different metadata. But segmentation seems to work fine and we can treat image as Gray16.

With images = ZenImage(2752,2208,ZenPixelType.Gray16,10,0,0) the result is strange. The viewer is occasionally showing the image as expected and occasionally showing fully black image (not just dark) but pipette tool may give ordinary pixel values which doesn’t correspond with the totally black image as viewed. But when trying segmentation on those images the result is also highly irregular and often treats the image as black.

Finally, we also tested Bgr48. The images are viewed correctly with no black images but pipette tool gives 0,0,0 for RGB values and the segmentation also follows these pixel values which makes it impossible to rely on.

Kind regards
Fredrik Olsson

Zen.Acquisition.StartLive()
#images = ZenImage(2752,2208,ZenPixelType.Bgr48,10,0,0)
#images = ZenImage(2752,2208,ZenPixelType.Gray16,10,0,0)
images = ZenImage()
for i in range(0,10):
a = Zen.Acquisition.AcquireImage()
images.AddSubImage(a,0,0,i)
Zen.Windows.ShowImage2d(a,True)

for i in range(1,11):
image = images.CreateSubImage('Z('+str(i)+')')
print image.Metadata.PixelType
Zen.Windows.ShowImage2d(b,True)
mask = Zen.Processing.Segmentation.Threshold(image,True)
user-4
Posts: 398
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Hello Fredrik Olsson,

this is a bit confusing but there is a ‘simple’ explanation for that

images = ZenImage()

generates an empty container!

The Code

images.AddSubImage(a,0,0,i)

adds an image with z-Position i to that container.

The 8 bit Gray in the in the viewer is a bug, as the metadata is not given and the viewer should look ‘deeper’ in the file. Therefore segmentation etc. work correctly as they really look at the image data itself.

But

images = ZenImage(2752,2208,ZenPixelType.Gray16,10,0,0)

generates a container with 10 images in z.

Therefore adding

images.AddSubImage(a,0,0,i)

results in 2 images at the same z-position if i is between 0 and 9.

In this case it depends on the algorithm, whether the first or the second image is found. This is the reason why you normally get a black image, which is the first image, but occasionally see the second image.

I hope this helps …
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

Hi,

Thanks for the clarification! I fully agree that there is a certain difference between an empty pre-allocated container of a certain type and a non-empty container of a certain type. :)

Please note that when inserting images of type 2752x2208 Gray16 (14 bits in reality) into an empty ZenImage() container Gray8 is showed as pixeltype for image.Metadata.Pixeltype where image is a created subimage from this container. They viewer Zen.Windows.ShowImage2d(image,True) works fine. However, when knowing this it is easy for me to workaround.

images = ZenImage()
for i in range(0,10):
a = Zen.Acquisition.AcquireImage()
images.AddSubImage(a,0,0,i)


for i in range(1,11):
image = images.CreateSubImage('Z('+str(i)+')')
print image.Metadata.PixelType #Shows Gray8
user-4
Posts: 398
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Hello Fredrik Olsson,

if you add all your images to the 'first' image like

Code: Select all

image1 = Zen.Application.LoadImage()
image2 = Zen.Application.LoadImage()
image1.AddSubImage(image2,0,0,1)
the pixeltype etc. should show up correctly!
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

Perfect! Many thanks!
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

Hi again,

Maybe I was a little too fast to in saying "perfect". It appears after some more verifications that the image acting as the container may randomly show up instead of the true added image at a certain position when the image is retrieved from the container. Se script below. I tried both to start adding the second image at both "0" position and "1" position.


My solution was to use the empty zen container only. However, apart from showing wrong pixeltype in the metadata the scaling/pixel seems to default to 1, which impacts some feature parameters, so some precautions needs to be made (in my case I kept track of correct scalign and applied a correction to affected parameters in the feature table) but otherwise its ok.

Kind regards
Fredrik Olsson

Code: Select all

Zen.Acquisition.StartLive()
xPos = Zen.Devices.Stage.ActualPositionX
yPos = Zen.Devices.Stage.ActualPositionY

for Count in range(0,10):
    xPos = xPos + 500
    Zen.Devices.Stage.MoveTo(xPos, yPos)

    if Count == 0:
        container = Zen.Acquisition.AcquireImage()
        #To faciliate use of first image
        first = Zen.Acquisition.AcquireImage()           
        #Zen.Windows.ShowImage2d(container, True)
    else:
        image = Zen.Acquisition.AcquireImage()
        #Zen.Windows.ShowImage2d(image, True)
        #First image added at index 1, have also tried adding at index 0.
        container.AddSubImage(image,0,0,Count)         

for i in range(2,container.Bounds.SizeZ+1):
    image = container.CreateSubImage('Z('+str(i)+')')
    print image.Metadata.PixelType
    #Container original image shows up randomly instead of the true added image.
    Zen.Windows.ShowImage2d(image, True)        

xPos = xPos - 5000
Zen.Devices.Stage.MoveTo(xPos, yPos)
Zen.Acquisition.StopLive()
print("Finished")
Post Reply