BiodataMiningGroup / quimbi

Quick exploration tool for multivariate bioimages
GNU General Public License v3.0
1 stars 0 forks source link

It's alive #1

Open mzur opened 6 years ago

mzur commented 6 years ago

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 commented 6 years ago

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()