Skip to content

Commit

Permalink
step3 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
huygensCortex committed Jul 22, 2024
1 parent afdef37 commit df852b4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 39 deletions.
15 changes: 13 additions & 2 deletions functions/SR_240222_cal_allob.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def cal_allob(ccel, TETC, rang):
for iv in range(0, ccel): # Adjusted to 1-based index
for its in rang:
if TETC[0][its] is not None: # Check if the array is not None and not empty
all_obj[iv, its] = np.sum(TETC[0][its] == iv) # Adjusted for 1-based index logic
all_obj[iv, its] = np.sum(TETC[0][its] == iv + 1) # Adjusted for 1-based index logic
else:
all_obj[iv, its] = -1

Expand Down Expand Up @@ -44,4 +44,15 @@ def main():
print(f'Cleaned image saved to {output_path}')

if __name__ == '__main__':
main()
main()


# ccel = 10
# all_obj = np.zeros((ccel, len(MATC[0])), dtype=np.uint16)

# for iv in range(ccel):
# for its in rang:
# if MATC[0][its] is not None:
# all_obj[iv][its] = np.sum(MATC[0][its] == iv + 1)
# else:
# all_obj[iv][its] = -1
94 changes: 57 additions & 37 deletions step3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
@author: samarth
"""

import os
import numpy as np
import scipy.io as sio
from skimage.io import imread
from skimage.morphology import skeletonize
from skimage.morphology import skeletonize, thin
from functions.SR_240222_cal_allob import cal_allob
from functions.SR_240222_cal_celldata import cal_celldata
from scipy.stats import mode
import matplotlib.pyplot as plt


# Define thresholds and parameters
pos = 'Pos0_2'
path = f'/Users/samarth/Documents/MATLAB/Full_Life_Cycle_tracking/Python_Track_Test/Pro/'
path = f'/Users/samarth/Documents/MATLAB/Full_Life_Cycle_tracking/Python_Track_Test/MAT/'
sav_path = '/Users/samarth/Documents/MATLAB/Full_Life_Cycle_tracking/saved_res/py_res/'
shock_period = [122, 134]

Expand All @@ -44,15 +44,16 @@
# for i in range(start, end + 1):
# mat_masks[i] = None

start = 0
for its in range(1, len(mat_masks) + 1):
if mat_masks[its] is not None and np.sum(mat_masks[its]) > 0:
start = -1
for its in range(len(mat_masks)):
# if mat_masks[its] is not None and np.sum(mat_masks[its]) > 0:
if np.sum(mat_masks[its]) > 0:
start = its
break

# Tracking all detections
print("Tracking All Detections")
if start != 0:
if start != -1:
rang = range(start, len(mat_masks))
I2 = mat_masks[start]
A = np.zeros_like(mat_masks[start])
Expand All @@ -76,7 +77,7 @@
# plt.title('uq')
# plt.show()

while xx != 0:
while xx != -1:
for im_no in rang2:
#I2 = mat_masks[im_no] if ccel == 1 else MATC[1][im_no]
if ccel == 1:
Expand All @@ -100,13 +101,13 @@
#TODO!
ind1 = np.unique(I2)[1:] # Exclude background
I3 = (I2 == ind1[0])
I3A = I3
I3A = I3.copy()
# plt.figure()
# plt.imshow(np.uint16(I3A), cmap='gray')
# plt.title('I3A')
# plt.show()
else:
I3A = IS6
I3A = IS6.copy()
# plt.figure()
# plt.imshow(np.uint16(I3A), cmap='gray')
# plt.title('I3A')
Expand All @@ -125,10 +126,10 @@
# plt.show()


plt.figure()
plt.imshow(np.uint16(I3B), cmap='gray')
plt.title('I3B')
plt.show()
# plt.figure()
# plt.imshow(np.uint16(I3B), cmap='gray')
# plt.title('I3B')
# plt.show()


ind = mode(I3B[I3B != 0])[0]
Expand All @@ -145,18 +146,30 @@


if ind == 0 and ccel == 1:
MATC[0][im_no] = I3B
MATC[1][im_no] = I2A
MATC[0][im_no] = I3B.copy()
MATC[1][im_no] = I2A.copy()
continue
elif ind == 0 and ccel != 1:
continue

pix = (I2A == ind)
pix0 = (I2A != ind)
pix = np.where(I2A == ind)
pix0 = np.where(I2A != ind)

# pix = np.flatnonzero(I2A == ind)
# pix0 = np.flatnonzero(I2A != ind)

# I2A.flat[pix] = ccel
# I2A.flat[pix0] = 0
# IS6 = I2A.copy()
# I22 = np.zeros_like(I2)
# pix1 = np.flatnonzero(IS6 == ccel)
# I2.flat[pix1] = 0
# pix2 = np.unique(I2)
# pix2 = pix2[1:]

I2A[pix] = ccel
I2A[pix0] = 0
IS6 = np.copy(I2A)
IS6 = I2A.copy()

"""
plt.figure()
Expand All @@ -166,29 +179,45 @@
"""

I22 = np.zeros_like(I2)
pix1 = (IS6 == ccel)
pix1 = np.where(IS6 == ccel)
I2[pix1] = 0

#TODO!
# #TODO!
pix2 = np.unique(I2)[1:] # Exclude background

if ccel == 1:
for ity in range(len(pix2)):
pix4 = np.where(I2 == pix2[ity])
I22[pix4] = ity + 1
MATC[0][im_no] = IS6
MATC[0][im_no] = IS6.copy()
else:
if pix2.size > 0:
for ity in pix2:
pix4 = np.where(I2 == ity)
I22[pix4] = ity
else:
I22 = I2
IS61 = MATC[0][im_no]
IS61 = (MATC[0][im_no]).copy()
IS61[pix] = ccel
MATC[0][im_no] = np.uint16(IS61)

MATC[1][im_no] = I22.astype(np.uint16)
MATC[0][im_no] = np.uint16(IS61.copy())

MATC[1][im_no] = I22.copy()
# if ccel == 1:
# for ity in range(len(pix2)):
# pix4 = np.flatnonzero(I2 == pix2[ity])
# I22.flat[pix4] = ity + 1 # Adjust for 0-based indexing in Python
# MATC[0][im_no - 1] = IS6.copy()
# else:
# if len(pix2) > 0:
# for ity in range(len(pix2)):
# pix4 = np.flatnonzero(I2 == pix2[ity])
# I22.flat[pix4] = ity + 1 # Adjust for 0-based indexing in Python
# else:
# I22 = I2
# IS61 = (MATC[0][im_no - 1]).copy()
# IS61.flat[pix] = ccel
# MATC[0][im_no - 1] = (IS61.copy()).astype(np.uint16)
# MATC[1][im_no - 1] = I22.copy()


# plt.figure()
Expand All @@ -197,7 +226,7 @@
# plt.show()


xx = 0
xx = -1
for i in rang:
if MATC[1][i] is not None and np.sum(MATC[1][i]) > 0:
xx = i
Expand All @@ -208,15 +237,6 @@

ccel -= 1 # number of cells tracked

# for x in rang2:
# tracked = MATC[1][x]
# plt.figure()
# plt.imshow(np.uint16(tracked) == 1, cmap='gray')
# plt.title('tracked')
# plt.show()




# Removing the shock-induced points from rang
rang3 = list(rang)
Expand Down

0 comments on commit df852b4

Please sign in to comment.