baroudlab / griottes Goto Github PK
View Code? Open in Web Editor NEWPython program to generate NetworkX graphs from segmented images.
Home Page: https://griottes.readthedocs.io
License: MIT License
Python program to generate NetworkX graphs from segmented images.
Home Page: https://griottes.readthedocs.io
License: MIT License
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:
G = graph_generation_func.generate_contact_graph(labels)
---------------------------------------------------------------------------
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!
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)
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.