Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's alive #1

Open
mzur opened this issue May 24, 2018 · 1 comment
Open

It's alive #1

mzur opened this issue May 24, 2018 · 1 comment

Comments

@mzur
Copy link
Member

mzur commented May 24, 2018

As it happens Quimbi still seems to run fine in a current browser. I'll see if I can reproduce Jan's input file format using the msiproc HDF5 some time. Then people might actually use this tool.

screen shot 2018-05-24 at 22 09 29

@mzur
Copy link
Member Author

mzur commented May 25, 2018

Works alright with one of Annika's full datasets (360x269x20000) and in realtime on my laptop.

screen shot 2018-05-25 at 11 25 05

Here is the draft of my script to convert HDF5 to the Quimbi format. The matrix box seems to get lost and the overlay image is not working yet:

# Parses a HDF5 MSI image to the Quimbi format
import sys
import os
import pandas as pd
import numpy as np
from PIL import Image

# in_path = 'data/20180322_AF_DHB_RP_mus_K_109_1_converted/20180322_AF_DHB_RP_mus_K_109_1_processed_norm.h5'
in_path = sys.argv[1]
out_path = sys.argv[2]

file = pd.HDFStore(in_path)
key = file.keys()[0]
data = file.get(key)

coordinates = np.array(data.index.tolist())[:, 0:2]
minimum = coordinates.min(axis=0)
maximum = coordinates.max(axis=0)
dimensions = maximum - minimum + 1

dataset_name = key.strip('/')
# Dataset information
print('{},data/{}/,.png,{},{},{}'.format(dataset_name, dataset_name, data.shape[1], dimensions[0], dimensions[1]))
# Preprocessing information
print('unknown')
# Brightfield overlay information
print('TODO')

global_max = data.max().max()
global_min = data.min().min()

chunk_size = 4
current_channel_index = 0
last_channel_index = data.shape[1]
image = np.zeros((dimensions[0], dimensions[1], 4), dtype=np.float32)
filename = []

for channel in data:
   image_channel_index = current_channel_index % chunk_size
   for coords, pixel in zip(coordinates, data[channel]):
      image[coords[0] - minimum[0], coords[1] - minimum[1], image_channel_index] = pixel

   current_channel_index += 1
   filename.append(str(channel))

   if image_channel_index == 3 or current_channel_index == last_channel_index:
      png_image = (image - global_min) / global_max * 255
      name = '{}/{}.png'.format(out_path, '-'.join(filename))
      Image.fromarray(png_image.astype(np.uint8)).save(name)
      print('-'.join(filename))
      filename = []

file.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant