Skip to content

Commit

Permalink
Removed tqdm dependence from the independent_analysis module
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkya-kulkarni committed Mar 2, 2023
1 parent fd44c32 commit a71883a
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import numpy as np
import pandas as pd
from tqdm.notebook import tqdm

from scipy import ndimage
from scipy.stats import circmean, circstd
Expand Down Expand Up @@ -740,22 +739,16 @@ def load_pandas_dataframe(results_array):

########################################################################################

def independent_analysis_function(filename, FilterKey, BinarizationKey, LocalDensityKey, DensityThresholdValueKey, LocalSigmaKey, ThresholdValueKey, SpacingKey, ScaleKey, FIGSIZE, DPI, PAD, FONTSIZE_TITLE, pad_fraction, aspect):
def independent_analysis_function(filename, FilterKey, LocalSigmaKey, ThresholdValueKey, SpacingKey, ScaleKey, FIGSIZE, DPI, PAD, FONTSIZE_TITLE, pad_fraction, aspect, mosiac_plot_filename, results_filename, BinarizationKey=20, LocalDensityKey=10, DensityThresholdValueKey=0.5):

########################################################################################

print()

pbar = tqdm(total = 10, desc = 'Analyzing', colour = 'green')

# Read the image
raw_image = convert_to_8bit_grayscale(filename)

# Filter the image
filtered_image = make_filtered_image(raw_image, FilterKey)

pbar.update(1)

###########################

# Calculate local density by binarizing the image first (using simple mean thresholding), then convoluting it with a nxn kernel of ones.
Expand All @@ -765,8 +758,6 @@ def independent_analysis_function(filename, FilterKey, BinarizationKey, LocalDen
# Binarize the image
binarized_image = binarize_image(filtered_image, radius = BinarizationKey)

pbar.update(1)

###########################

# Define the kernel and it's size
Expand All @@ -782,8 +773,6 @@ def independent_analysis_function(filename, FilterKey, BinarizationKey, LocalDen

Local_Density = np.divide(Local_Density, Local_Density.max(), out=np.full(Local_Density.shape, np.nan), where=Local_Density.max() != 0)

pbar.update(1)

###########################

# Calculate the fibrotic_percentage area of the non-zero pixels compared to the image size
Expand All @@ -793,50 +782,37 @@ def independent_analysis_function(filename, FilterKey, BinarizationKey, LocalDen

fibrotic_percentage = percentage_area(Local_Density_considered)

pbar.update(1)

###########################

# Calculate image gradients in X and Y directions
image_gradient_x, image_gradient_y = make_image_gradients(filtered_image)

pbar.update(1)

###########################

# Calculate the structure tensor and solve for EigenValues, EigenVectors
Structure_Tensor, EigenValues, EigenVectors, Jxx, Jxy, Jyy = make_structure_tensor_2d(image_gradient_x, image_gradient_y, LocalSigmaKey)

pbar.update(1)

###########################

# Calculate Coherence

Image_Coherance = make_coherence(filtered_image, EigenValues, Structure_Tensor, ThresholdValueKey)

pbar.update(1)

###########################

# Calculate Orientation
Image_Orientation = make_orientation(filtered_image, Jxx, Jxy, Jyy, ThresholdValueKey)
vx, vy = make_vxvy(filtered_image, EigenVectors, ThresholdValueKey)

pbar.update(1)

###########################

# Plot the results

fig = make_mosiac_plot(raw_image, binarized_image, filtered_image, Local_Density, Image_Coherance, Image_Orientation, vx, vy, filename, LocalSigmaKey, fibrotic_percentage, SpacingKey, ScaleKey, FIGSIZE, DPI, PAD, FONTSIZE_TITLE, pad_fraction, aspect)

saving_name = 'Results' + filename + '_LocalSigma_' + str(LocalSigmaKey) + '.png'
plt.savefig(saving_name)
plt.savefig(mosiac_plot_filename)
plt.close()

pbar.update(1)

###########################

# Perform statistical analysis
Expand All @@ -850,17 +826,7 @@ def independent_analysis_function(filename, FilterKey, BinarizationKey, LocalDen

# Save the dataframe in a CSV file

saving_name = 'Results' + filename + '_LocalSigma_' + str(LocalSigmaKey) + '.csv'

dataframe.to_csv(saving_name, index=False)

pbar.update(1)

###########################

pbar.close()

print()
dataframe.to_csv(results_filename, index=False)

########################################################################################

0 comments on commit a71883a

Please sign in to comment.