{"id":16181125,"url":"https://github.com/mrsamsonn/monolithic-polylithic-crystal-segmentation","last_synced_at":"2026-04-28T11:03:42.932Z","repository":{"id":252662381,"uuid":"841078560","full_name":"mrsamsonn/Monolithic-Polylithic-Crystal-Segmentation","owner":"mrsamsonn","description":"A grid segmentation algorithm for clustering crystal structures using diffraction patterns. Useful in material science and nanotechnology, this code enables detailed analysis of crystals for research and industrial applications.","archived":false,"fork":false,"pushed_at":"2025-04-06T22:42:45.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T23:25:48.222Z","etag":null,"topics":["clustering","crystal-structure","crystallography","data-analysis","diffraction-patterns","grid-segmentation","image-processing","k-means","machine-learning","matertial-science","nanotechnology","python","research-project","research-tools","scientific-computing"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrsamsonn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-11T15:22:09.000Z","updated_at":"2025-04-06T22:42:48.000Z","dependencies_parsed_at":"2025-04-06T23:21:58.321Z","dependency_job_id":"ca0fe3c2-b395-47a3-ba72-85bcc4b5b656","html_url":"https://github.com/mrsamsonn/Monolithic-Polylithic-Crystal-Segmentation","commit_stats":null,"previous_names":["mrsamsonn/monolithic-polylithic-crystal-segmentation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrsamsonn/Monolithic-Polylithic-Crystal-Segmentation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsamsonn%2FMonolithic-Polylithic-Crystal-Segmentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsamsonn%2FMonolithic-Polylithic-Crystal-Segmentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsamsonn%2FMonolithic-Polylithic-Crystal-Segmentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsamsonn%2FMonolithic-Polylithic-Crystal-Segmentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrsamsonn","download_url":"https://codeload.github.com/mrsamsonn/Monolithic-Polylithic-Crystal-Segmentation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrsamsonn%2FMonolithic-Polylithic-Crystal-Segmentation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32377599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clustering","crystal-structure","crystallography","data-analysis","diffraction-patterns","grid-segmentation","image-processing","k-means","machine-learning","matertial-science","nanotechnology","python","research-project","research-tools","scientific-computing"],"created_at":"2024-10-10T06:12:11.883Z","updated_at":"2026-04-28T11:03:42.924Z","avatar_url":"https://github.com/mrsamsonn.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monolithic-Polylithic Crystal Segmentation\n\nThis project provides a grid-based segmentation approach to identify monolithic and polylithic crystal structures from diffraction patterns. The method partitions diffraction data into grids, detects peaks in each tile, extracts features, and applies k-means clustering for grouping similar diffraction patterns.\n\n## Clustered Output Examples\n ![animated_plot](https://github.com/user-attachments/assets/b88677aa-dcc2-4830-8c0a-a34aa9fa2030)\n \u003cimg width=\"240\" alt=\"Screenshot 2024-08-16 at 12 49 22 PM\" src=\"https://github.com/user-attachments/assets/687860e8-5789-4e8c-9a49-b7fea5fbd1a8\"\u003e\n \u003cimg width=\"366\" alt=\"Screenshot 2024-08-16 at 12 49 31 PM\" src=\"https://github.com/user-attachments/assets/4e69d6d6-e2f6-4011-ba62-a9b21d8cfb16\"\u003e\n\n## Table of Contents\n- [Output Example](#output-example)\n- [Overview](#overview)\n- [Algorithm Explanation](#algorithm-explanation)\n- [Setup Instructions](#setup-instructions)\n- [Usage](#usage)\n- [Output](#output)\n- [Project Structure](#project-structure)\n- [Future Work](#future-work)\n- [License](#license)\n\n## Overview\n\nThis project segments diffraction patterns into square grids, each analyzed for peak detection. The algorithm then clusters the grids using k-means and visualizes the segmented diffraction patterns to identify monolithic vs. polylithic structures.\n\n## Algorithm Explanation\n\nThe segmentation algorithm follows a structured approach:\n\n### 1. **Grid Partitioning**\nFirst, the diffraction pattern is divided into square grids. Each grid cell is treated as a separate region for analysis.\n\n```python\nimport numpy as np\n\ndef create_grid(data, grid_size):\n    \"\"\"\n    Divides the diffraction data into square grids based on the given grid size.\n    \"\"\"\n    rows, cols = data.shape\n    grid_rows = rows // grid_size\n    grid_cols = cols // grid_size\n    grids = []\n\n    for i in range(grid_rows):\n        for j in range(grid_cols):\n            grid = data[i*grid_size:(i+1)*grid_size, j*grid_size:(j+1)*grid_size]\n            grids.append(grid)\n    \n    return grids\n\n```\n\n2. Peak Detection\n\nFor each grid, local maxima are identified using a peak detection algorithm. The scipy.signal.find_peaks function is often employed for this purpose.\n\nfrom scipy.signal import find_peaks\n\n```python\ndef detect_peaks(grid):\n    \"\"\"\n    Detects peaks in the grid data using scipy's find_peaks function.\n    \"\"\"\n    peaks, _ = find_peaks(grid)\n    return peaks\n```\n\n3. Feature Extraction\n\nFor each grid, features such as peak intensity and spatial distribution are extracted into a feature vector. These features are essential for clustering.\n\n```python\ndef extract_features(grid, peaks):\n    \"\"\"\n    Extracts features from the grid based on the detected peaks.\n    \"\"\"\n    features = []\n    for peak in peaks:\n        intensity = grid[peak]  # Peak intensity\n        position = peak  # Peak position (x, y)\n        features.append([intensity, position])\n    \n    return np.array(features)\n```\n\n4. Clustering\n\nThe features are clustered using k-means. The optimal number of clusters is determined using the elbow method.\n\n```python\nfrom sklearn.cluster import KMeans\n\ndef cluster_features(features, n_clusters=3):\n    \"\"\"\n    Clusters the feature vectors using k-means clustering.\n    \"\"\"\n    kmeans = KMeans(n_clusters=n_clusters)\n    clusters = kmeans.fit_predict(features)\n    return clusters\n```\n\n5. Visualization\n\nFinally, the clusters are visualized using matplotlib. Each grid cell is colored based on the cluster it belongs to.\n\n```python\nimport matplotlib.pyplot as plt\n\ndef plot_clusters(clusters, grid_size, data_shape):\n    \"\"\"\n    Visualizes the clustered data with color coding.\n    \"\"\"\n    rows, cols = data_shape\n    grid_rows = rows // grid_size\n    grid_cols = cols // grid_size\n\n    # Create an empty image for the cluster visualization\n    cluster_image = np.zeros((rows, cols))\n\n    idx = 0\n    for i in range(grid_rows):\n        for j in range(grid_cols):\n            cluster_image[i*grid_size:(i+1)*grid_size, j*grid_size:(j+1)*grid_size] = clusters[idx]\n            idx += 1\n\n    plt.imshow(cluster_image, cmap='viridis')\n    plt.title('Cluster Visualization')\n    plt.colorbar()\n    plt.show()\n```\n\nSetup Instructions\n\nPrerequisites\n\t•\tPython 3.x\n\t•\tJupyter Notebook\n\nInstall Dependencies\n\n```\npip install numpy matplotlib scikit-learn tifffile\n```\n\nClone and Run\n\n```\ngit clone https://github.com/mrsamsonn/Monolithic-Polylithic-Crystal-Segmentation.git\ncd Monolithic-Polylithic-Crystal-Segmentation\njupyter notebook Grid_Segmentation.ipynb\n```\n\nUsage\n\t1.\tOpen Grid_Segmentation.ipynb in Jupyter Notebook.\n\t2.\tFollow the instructions to load diffraction data, define grid parameters, and run the segmentation algorithm.\n\nOutput\n\nThe segmentation process outputs:\n\t•\tAnimated GIFs showing the clustering process.\n\t•\tStatic images with color-coded clusters.\n\t•\tLegends and clustering metrics.\n\nProject Structure\n\n```\nMonolithic-Polylithic-Crystal-Segmentation/\n│\n├── Grid_Segmentation.ipynb   # Main analysis notebook\n├── animated_plot.gif         # Example output GIF\n├── *.png                     # Sample output images\n├── README.md                 # Project documentation\n└── data/                     # Input diffraction files (user-provided)\n```\n\nFuture Work\n\t•\tDynamic Grid Resizing: Implement adaptive grid resizing based on the size of detected structures.\n\t•\tAdvanced Clustering: Incorporate DBSCAN or spectral clustering for better handling of noisy diffraction data.\n\t•\tReal-Time Analysis: Support live data processing for real-time diffraction pattern segmentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsamsonn%2Fmonolithic-polylithic-crystal-segmentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrsamsonn%2Fmonolithic-polylithic-crystal-segmentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrsamsonn%2Fmonolithic-polylithic-crystal-segmentation/lists"}