<jupyter_start><jupyter_text>Purpose: Phuong BeV Microglia OGD Cell Analysis  Purpose: To quantify cell features of already segmented microglia images from step 1 in this folder Created by: <NAME> Creation Date: 06/4/2021 (Original file)Edit Date: 10/27/2021 - Change the file to be for Phuongs BeV Analysis rather than the Australian Pig Project *Step 1: Import Necessary Packages*<jupyter_code>import numpy as np
import pandas as pd
from scipy import ndimage

import skimage.filters
from skimage import morphology
from skimage.measure import label, regionprops, regionprops_table
from skimage.color import label2rgb
from skimage import io
from skimage import measure 

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

import watermark
import os
from PIL import Image<jupyter_output><empty_output><jupyter_text>*Step 2: User Inputs*<jupyter_code>#replace the example path from my computer with the path to the image on your computer

cell_folder = '/Users/hhelmbre/Desktop/Phuong_Bev/li_thresh'

file_type = '.npy'<jupyter_output><empty_output><jupyter_text>*Step 3: Defining a Folder Cleaner Function to only Return Tif Images*<jupyter_code>def folder_cleaner(folder, image_type):
    k=0
    for files in folder:
        if image_type in str(files):
            k+=1
        else:
            folder = np.delete(folder, np.argwhere(folder == str(files)))
    return folder<jupyter_output><empty_output><jupyter_text>*Step 4: Get All Images in the Folder*<jupyter_code>arr = os.listdir(cell_folder)
file_list = np.asarray(arr)
file_list = folder_cleaner(file_list, file_type)
file_list<jupyter_output><empty_output><jupyter_text>*Step 5: Segmenting and Calculating Region Features on All Images*<jupyter_code>properties_list = ('area', 'bbox_area', 'centroid', 'convex_area', 
                   'eccentricity', 'equivalent_diameter', 'euler_number', 
                   'extent', 'filled_area', 'major_axis_length', 
                   'minor_axis_length', 'orientation', 'perimeter', 'solidity')

j = 0
for names in file_list:
        file_name = str(cell_folder + '/' + names)
        new_binary_li = np.load(file_name)
        label_image = label(new_binary_li)
        
        #Feel free to add them here as well. The computational time is pretty efficient
        props = measure.regionprops_table(label_image, properties=(properties_list))

        if j == 0:
            df = pd.DataFrame(props)
            df['filename'] = names
        else:
            df2 = pd.DataFrame(props)
            df2['filename'] = names
            df = df.append(df2)

        j = 1<jupyter_output><empty_output><jupyter_text>*Step 6: Caculating the Circularity*<jupyter_code>df['circularity'] = 4*np.pi*df.area/df.perimeter**2<jupyter_output><empty_output><jupyter_text>*Step 7: Calculating the Aspect Ratio*<jupyter_code>df['aspect_ratio'] = df.major_axis_length/df.minor_axis_length<jupyter_output><empty_output><jupyter_text>*Step 8: Add in a column for the ID*<jupyter_code>df<jupyter_output><empty_output><jupyter_text>*Step 10: Saving as a CSV file*<jupyter_code>df.to_csv('/Users/hhelmbre/Desktop/Phuong_BeV/10_27_2021_li_threshold_all_data.csv')<jupyter_output><empty_output><jupyter_text>*Step 11: Print Dependencies and State*<jupyter_code>%load_ext watermark

%watermark -v -m -p numpy,pandas,scipy,skimage,matplotlib,wget

%watermark -u -n -t -z<jupyter_output>Python implementation: CPython
Python version       : 3.7.4
IPython version      : 7.8.0

numpy     : 1.17.2
pandas    : 0.25.1
scipy     : 1.3.1
skimage   : 0.17.2
matplotlib: 3.1.1
wget      : 3.2

Compiler    : Clang 4.0.1 (tags/RELEASE_401/final)
OS          : Darwin
Release     : 20.6.0
Machine     : x86_64
Processor   : i386
CPU cores   : 8
Architecture: 64bit

Last updated: Wed Oct 27 2021 15:19:20PDT
{'fraction_non_alphanumeric': 0.09655353854248881, 'fraction_numerical': 0.027624309392265192, 'mean_word_length': 4.103355704697987, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '254613', 'license': 'MIT', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1306, 'n_words': 324, 'path': 'Phuong_BeV /2_Phuong_collab_segmentation.ipynb', 'repo_name': 'Nance-Lab/cellmorphflows', 'size': '3812'}