Giter Club home page Giter Club logo

Comments (8)

sweep-ai avatar sweep-ai commented on August 11, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

Hey @retroam,

I've started working on turning the app into a CLI tool. The plan is to convert the MATLAB scripts to Python for consistency and ease of packaging. I'll also modify the existing Python scripts to accept command line arguments for input and output directories. Lastly, I'll create a main script that ties all the functions together and serves as the entry point of the CLI tool.

Give me a minute!

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

# Calcium-analysis
Python implementation of calcium imaging analysis pipeline for cardiac myocytes for [Automated image analysis of cardiac myocyte Ca2+ dynamics](https://pubmed.ncbi.nlm.nih.gov/22255377/)

import numpy as np
from skimage import measure
import os
def roi_to_data(roi_file, image_file):
"""
Extract data from regions of interest in an image stack.
This function loads a labeled image (from a .npy file), computes
the mean intensity of each labeled region in each image in a stack,
and saves the results.
"""
# Load the labeled image and the image stack
labels = np.load(roi_file)
I_t = np.load(image_file)
# Extract data from each region in each image
data = []
bkg = []
for I in np.rollaxis(I_t, axis=2):
# Get properties of labeled regions
props = measure.regionprops(labels, intensity_image=I)
# Compute the mean intensity of each region and the background
avg = [prop.mean_intensity for prop in props]
I_bkg = I.copy()
for prop in props:
I_bkg[prop.coords[:, 0], prop.coords[:, 1]] = np.nan
bkg_intensity = np.nanmean(I_bkg)
data.append(avg)
bkg.append(bkg_intensity)
# Save the results
np.save('data.npy', data)
np.save('bkg.npy', bkg)
# Return the results

import unittest
import numpy as np
import os
from PIL import Image
import image_processing # assuming the module is named image_processing.py
class TestImageProcessing(unittest.TestCase):
def test_load_image(self):
# Test loading a single image
image_path = 'path_to_a_test_image.tif'
I, info = image_processing.load_image(image_path)
self.assertIsInstance(I, np.ndarray)
self.assertIsInstance(info, dict)
self.assertEqual(I.shape[0], info['ImageLength'])
self.assertEqual(I.shape[1], info['ImageWidth'])
if __name__ == '__main__':

function[I_t] = imagestostacks(image_fld,save_fld)
% IMAGESTOSTACKS(image_fld,save_fld) assembles tif images in image_fld as
% a single matrix which is then saved in save_fld as a .mat file
% NOTE: tif files in image_fld have to be labelled as image01...09,10 etc.
%Example:
% I = imagestostacks(image_fld,save_fld);
cd(image_fld);
i_bloc = dir('*.tif*');
I_t = [];
for j = 1:length(i_bloc)
info = imfinfo(i_bloc(j).name);
fileName{j} = i_bloc(j).name;
num_images = numel(info);
I_cum = zeros(info(1,1).Height,info(1,1).Width,num_images-1);%pre-alloc
disp(['Loading tif file ' num2str(j) ' of ' num2str(length(i_bloc))]);
for k = 1:num_images
I = imread(i_bloc(j).name, k, 'Info', info);
I_cum(:,:,k) = I;
end
close all force;
I_t = cat(3,I_cum,I_t);
clear I_cum;
end
save([save_fld '\I.mat'],'I_t');

function[CC,I_mean,I_bw2,I_overlay] = stackstoroi(save_fld,sd)
% STACKSTOROI(image_fld,sd) loads *I*.mat from save_fld for image
% segmentation. sd is how many standard deviations above the mean the
% threshold is set for segmentation. Outputs:
% CC: connected components found in I_bw2
% I_mean: averaged image of *I*.mat
% I_bw2: binary image containing image segementation of *I*.mat
% I_overlay: overlay of identified ROI over I_mean
%Example:
% [CC,I_mean,I_bw2,I_overlay] = stackstoroi(save_fld,sd);
cd(save_fld);
m_bloc = dir('*I*.mat*');
I_cum = [];
img_content = [];
if length(m_bloc)== 11
for i = 1:11
I_cum = cat(3,I_cum,importdata(m_bloc(i).name));
end
else
I_cum = importdata(m_bloc(1).name);
end
for j = 1:length(I_cum)
I = I_cum(:,:,j);
img_content(j) = mean(I(:));
end
[marks,locs] = findpeaks(img_content,'minpeakdistance',100);
I_mean = mean(I_cum(:,:,locs),3);
%I_bw1 = bwspecial(otsu(I_mean,3));
I_bw1 = threshold(I_mean,mode(I_mean(:))+ sd*mad(I_mean(:),1));
I_bw2 = bwareaopen(I_bw1,20,4);
CC = bwconncomp(I_bw2);
I_edge = edge(I_bw2);
I_overlay = I_mean;
I_overlay(I_edge) = 10*max(I_mean(:))/9;


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

sweep-ai avatar sweep-ai commented on August 11, 2024

Hey @retroam,

I've started working on turning the app into a CLI tool. The plan is to use the existing run_analysis function as the main entry point for the CLI tool and add argument parsing to specify the necessary parameters. I'll be creating a new file to handle the command line interface and making a small modification to the run_analysis.py file.

Give me a minute!

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

import numpy as np
import scipy
import matcompat
image_fld = 'C:\Users\rka2p\Desktop\Calcium analysis\file_folder'
save_fld = 'C:\Users\rka2p\Desktop\Calcium analysis\save_folder'
imagestostacks(image_fld,save_fld)
#sd from mean of image intensity to set as threshold
sd = 7
[CC,I_mean,I_bw2,I_overlay] = stackstoroi(save_fld,sd)
imagesc(I_overlay)
axis off
[data,bkg] = roitodata(save_fld)

# Calcium-analysis
Python implementation of calcium imaging analysis pipeline for cardiac myocytes for [Automated image analysis of cardiac myocyte Ca2+ dynamics](https://pubmed.ncbi.nlm.nih.gov/22255377/)

import unittest
import numpy as np
import os
from PIL import Image
import image_processing # assuming the module is named image_processing.py
class TestImageProcessing(unittest.TestCase):
def test_load_image(self):
# Test loading a single image
image_path = 'path_to_a_test_image.tif'
I, info = image_processing.load_image(image_path)
self.assertIsInstance(I, np.ndarray)
self.assertIsInstance(info, dict)
self.assertEqual(I.shape[0], info['ImageLength'])
self.assertEqual(I.shape[1], info['ImageWidth'])
if __name__ == '__main__':

function[I_t] = imagestostacks(image_fld,save_fld)
% IMAGESTOSTACKS(image_fld,save_fld) assembles tif images in image_fld as
% a single matrix which is then saved in save_fld as a .mat file
% NOTE: tif files in image_fld have to be labelled as image01...09,10 etc.
%Example:
% I = imagestostacks(image_fld,save_fld);
cd(image_fld);
i_bloc = dir('*.tif*');
I_t = [];
for j = 1:length(i_bloc)
info = imfinfo(i_bloc(j).name);
fileName{j} = i_bloc(j).name;
num_images = numel(info);
I_cum = zeros(info(1,1).Height,info(1,1).Width,num_images-1);%pre-alloc
disp(['Loading tif file ' num2str(j) ' of ' num2str(length(i_bloc))]);
for k = 1:num_images
I = imread(i_bloc(j).name, k, 'Info', info);
I_cum(:,:,k) = I;
end
close all force;
I_t = cat(3,I_cum,I_t);
clear I_cum;
end
save([save_fld '\I.mat'],'I_t');

import numpy as np
import pytest
from calcium_analysis.image_segmentation import stack_to_roi
def test_stack_to_roi():
# Create a mock image stack
image_stack = np.random.rand(100, 100, 10)
# Call stack_to_roi with the mock image stack and a standard deviation value
labels, I_mean, I_bw2 = stack_to_roi(image_stack, 1)
# Assert that the returned labels, mean image, and binary image have the expected shapes and types
assert isinstance(labels, np.ndarray)
assert labels.shape == (100, 100)
assert isinstance(I_mean, np.ndarray)
assert I_mean.shape == (100, 100)
assert isinstance(I_bw2, np.ndarray)
assert I_bw2.shape == (100, 100)


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from calcium-analysis.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.