Giter Site home page Giter Site logo

baroudlab / griottes Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 4.0 5.93 MB

Python program to generate NetworkX graphs from segmented images.

Home Page: https://griottes.readthedocs.io

License: MIT License

Dockerfile 0.02% Python 5.05% Jupyter Notebook 94.93%

griottes's People

Contributors

aaristov avatar ajinkya-kulkarni avatar gronteix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

griottes's Issues

Unable to create a graph

Hi Gustave,

I was checking your library, hoping to create a napari plugin. Below are the steps I went through before stubling at the error:

  1. I open test image in napari (cells3D)
    image
  2. I segmented the nuclei and created a labelled mask
    image
  3. I loaded this labels into jupyter:
    image
  4. And finally I tried to create a graph using the command from the tutorial G = graph_generation_func.generate_contact_graph(labels)
    The error I've got:
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-15-44149e326267> in <module>
----> 1 G = graph_generation_func.generate_contact_graph(labels)

~/miniconda3/envs/nd2/lib/python3.8/site-packages/griottes/graphmaker/graph_generation_func.py in generate_contact_graph(user_entry, mask_channel, min_area, analyze_fluo_channels, fluo_channel_analysis_method, radius, descriptors)
    540     if isinstance(user_entry, np.ndarray):
    541 
--> 542         user_entry = create_region_contact_frame(
    543             user_entry,
    544             flat_image=True,

~/miniconda3/envs/nd2/lib/python3.8/site-packages/griottes/graphmaker/graph_generation_func.py in create_region_contact_frame(label_img, mask_channel, flat_image, min_area, analyze_fluo_channels, fluo_channel_analysis_method, radius)
    468         edge_frame = get_region_contacts(label_img[..., mask_channel])
    469     else:
--> 470         edge_frame = get_region_contacts(label_img)
    471 
    472     # get the region properties

~/miniconda3/envs/nd2/lib/python3.8/site-packages/griottes/graphmaker/graph_generation_func.py in get_region_contacts(mask_image)
    411     """
    412 
--> 413     assert np.ndim(mask_image) == 2
    414 
    415     # final output

AssertionError: 

Why doesn't it work with 3D labels???

Thanks in advance!

Issue with generating Figure_4.ipynb figure

Hi, I was trying to run Figure_4.ipynb, I managed to get all variables but at the end I'm not able to plot. Is it possible for you to check the final plotting function?
Screen Shot 2022-04-19 at 14 49 30
?

Weird axes order in test dataset zebrafish_brain_cell_labels.tif

In the test dataset the channels are in the last dimension and as there is 5 of them. The problem is that the standard data readers struggle with this format (can be seen in Fiji or napari --- same result). Would it be possible to put the channels axis first instead? Ideally the axis order should comply with ImageJ format, which is 'tzcyxs'. ImageJ tif can also carry along the channels metadata, which allows for correct data rendering.

What I usually do to save my data in Fiji-ready format:

grey = np.array([np.arange(256)] * 3, dtype='uint8')
red = np.array([np.arange(256), np.zeros((256,)), np.zeros((256,))], dtype='uint8')
green = np.array([np.zeros((256,)), np.arange(256), np.zeros((256,))], dtype='uint8')
blue = np.array([np.zeros((256,)), np.zeros((256,)), np.arange(256)], dtype='uint8')

META_ALIGNED = {'ImageJ': '1.53c',
 'images': 3,
 'channels': 3,
 'hyperstack': True,
 'mode': 'composite',
 'unit': '',
 'loop': False,
 'min': 1878.0,
 'max': 30728.0,
 'Ranges': (1878.0, 30728.0, 430.0, 600.0, 0.0, 501.0),
 'LUTs': [grey, green, blue]
 }

tifffile.imwrite(path, cyx_stack, imagej=True, metadata=META_ALIGNED)

Cannot plot graphs with labelled image as the input

Hello developers, I am trying to visualize the contact and geometric graphs from a labelled image. Somehow the network is unconnected, and I have no idea why.
I am attaching the sample code here, as well as the link to my labelled image (which is a 2D numpy array).
Thanks!

from griottes import generate_contact_graph, generate_geometric_graph, plot_2D
import numpy as np
import urllib.request

import matplotlib.pyplot as plt
import networkx as nx

url = 'https://github.com/ajinkya-kulkarni/PySpatialHistologyAnalysis/raw/main/labelled_image.npy'
filename = 'labelled_image.npy'

# Download the file from the URL and save it locally
urllib.request.urlretrieve(url, filename)

# Load the downloaded file as a numpy array
labelled_image = np.load(filename)

# Display the shape of the loaded numpy array
print(labelled_image.shape, labelled_image.min(), labelled_image.max())

plt.imshow(labelled_image)
plt.xticks([])
plt.yticks([])
plt.show()

G_contact = generate_contact_graph(labelled_image, analyze_fluo_channels = False)

G_geometric = generate_geometric_graph(labelled_image, analyze_fluo_channels=False, distance = 60)

plot_2D(G_contact, background_image = None, include_weights = True, figsize = (5,5), alpha_line = 0.5, scatterpoint_size = 5, legend = True, edge_color = 'w', line_factor = 0.1)

plot_2D(G_geometric, background_image = None, figsize = (5,5), alpha_line = 1, scatterpoint_size = 5, legend = True, edge_color = 'w', line_factor = 2)

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.