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

Poor cell segmentation #127

Open
RandallJEllis opened this issue Mar 24, 2023 · 2 comments
Open

Poor cell segmentation #127

RandallJEllis opened this issue Mar 24, 2023 · 2 comments

Comments

@RandallJEllis
Copy link

I am getting cell segmentations that look pretty bad, and I think it might be because of how I am preparing the videos. Screenshots of the cell segmentations on the raw bigTIFF video and the preprocessed (downsampled 4x, turbo-reg'd, dfof) video are below:

Raw:
raw_movie

Pre-processed
dfof_movie

I think the problem might be how I am preparing the bigTIFF video. The video is prepared from TIF images using the following script:

import cv2
import os
import numpy as np
from tqdm import tqdm
from tifffile import *

def tif_to_video(input_path, output_filename):

    # Define the location of the TIF files
    dir_path = f'{input_path}'

    # List of TIF files
    tif_files = [f for f in os.listdir(dir_path) if f.endswith('.TIF')]

    # Sort image filenames by number following 'p' in filename
    framenums = []
    for tif_file in tif_files:
        p_idx = tif_file.find('p')
        underscore_idx = tif_file[p_idx:].find('_')
        framenum = tif_file[p_idx+1:p_idx+underscore_idx]
        framenums.append(int(framenum))
    
    # order filenames in a list
    tif_files = [tif_file for _, tif_file in sorted(zip(framenums, tif_files))]

    ### bigTIFF ###
    output_file = f'{output_filename}.tif'

    arr_list = []
    # Iterate over the TIF files, import and add each TIF frame to arr_list
    for i, tif_file in tqdm(enumerate(tif_files)):
        img = cv2.imread(os.path.join(dir_path, tif_file), 0)
        img = img[...,None] # add third dimension (i.e., frame)
        arr_list.append(img)
    
    # concatenate frames into numpy array
    tiff_arr = np.concatenate(arr_list, axis=2)
    
    # export numpy array in bigTIFF format at 20 FPS
    with TiffWriter(output_file, bigtiff=True) as tif:
        for frame in np.transpose(tiff_arr,(2,0,1)):
            tif.write(frame, metadata={'fps':20.0}, compression='JPEG')    

Any help with this is greatly appreciated. Thanks in advance!

@bahanonu
Copy link
Owner

Would you be able to send me a folder with a subset of the raw TIF files? Also, what region and indicator/sensor are you imaging? That'll help me get a sense for what it should look like and anything that might need to be changed.

I can also get back with a line or two of code to load and save TIFF file series as a HDF5 using ciatah functions if that helps.

@RandallJEllis
Copy link
Author

RandallJEllis commented Mar 25, 2023

Hi Biafra,

Would you be able to send me a folder with a subset of the raw TIF files? Also, what region and indicator/sensor are you imaging? That'll help me get a sense for what it should look like and anything that might need to be changed.

Just emailed you a tar.gz of the first 100 frames because it was too big to attach here. The indicator is gcamp6f, and the data are from tumor spheroids, not in the brain.

I can also get back with a line or two of code to load and save TIFF file series as a HDF5 using ciatah functions if that helps.

Would definitely appreciate you sending this! Thank you!

Best,

Randy

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

2 participants