跳到正文
DEV Community· Aman Ayubkhan Pathan·· 3 小時前AI 評分38

NeuroTrace:如何將腦部 MRI 分割轉化為以證據為本的研究工作流程

NeuroTrace: Turning Brain MRI Segmentation into an Evidence-Driven Research Workflow

AI 導讀

NeuroTrace 將腦部 MRI 腫瘤分割、互動式視覺化、確定性定量分析及 AI 輔助研究整合為開源研究平台。平台採用約 1.41 million parameters 的預訓練 3D U-Net,支援 CPU 推理。Gemma 4 透過 Gemini API 或本機確定性綜合模式提供研究輔助;原始 MRI 數據保留在本機,AI 助手接收結構化資料及計算結果。

正文

This is a submission for the MLH x DEV Writing Challenge

What I Built

NeuroTrace — From Segmentation to Evidence.

Brain MRI segmentation is an important part of computational neuroimaging research. Deep learning models can identify potential tumor regions, but obtaining a segmentation mask is only one part of the workflow.

Researchers still need to inspect the results, visualize the segmentation in different anatomical planes, calculate meaningful measurements, perform quality checks and document their findings.

These activities are often spread across multiple tools.

I wanted to explore a different approach: What if segmentation, visualization, quantitative analysis and AI-assisted research could exist within one integrated workflow?

That idea became NeuroTrace — an Agentic Brain MRI Segmentation Analysis & Research Copilot.

NeuroTrace is an open-source research platform that combines an existing trained 3D U-Net segmentation model with interactive visualization, deterministic computational analysis, Google's Gemma 4 and research report generation.

The objective is not to replace researchers or make clinical decisions. It is to make the computational research workflow more accessible, structured and reproducible.

1. The segmentation engine: NeuroSegNet

At the core of NeuroTrace is a pretrained 3D U-Net model that performs brain tumor segmentation using FLAIR MRI volumes.

One of the decisions I made early was to preserve the existing trained model rather than build an entirely new architecture just for the hackathon.

The integrated model has:

  • One input channel.
  • Two output classes.
  • Approximately 1.41 million parameters.
  • A pretrained PyTorch checkpoint.

The application supports CPU inference, so a CUDA-enabled GPU is not mandatory.

The MRI is loaded as a NIfTI volume, validated and preprocessed before inference. The resulting segmentation mask is exported while preserving the reference scan's spatial geometry.

2. Interactive 2D and 3D visualization

A segmentation mask is difficult to interpret when it is presented only as a file or a numerical array.

I wanted visualization to be a central part of NeuroTrace rather than an additional feature.

The platform includes:

Multi-planar 2D visualization

  • Axial views.
  • Coronal views.
  • Sagittal views.
  • Segmentation overlays and contours.
  • Synchronized slice navigation.
  • Adjustable overlay opacity.

Interactive 3D visualization

  • Brain MRI volume rendering.
  • Separate tumor segmentation isosurface.
  • Independent visibility controls.
  • Adjustable opacity and lighting.
  • Camera controls for rotation, zoom and exploration.

The 3D viewer uses Plotly volume and isosurface rendering, with downsampling options to make visualization more practical.

3. Deterministic quantitative analysis

Another important part of NeuroTrace is moving beyond visual inspection.

The analysis layer calculates:

  • Tumor voxel count.
  • Physical tumor volume in millilitres.
  • Bounding box and spatial extent.
  • Centroids in voxel and scanner coordinates.
  • Brain volume fraction.
  • Slice-wise tumor distribution.

An important implementation detail is that physical volume is calculated using the actual voxel spacing obtained from the NIfTI geometry.

The calculation is:

Volume (mL) = Tumor voxels × dx × dy × dz / 1000

This avoids assuming that every MRI scan has identical voxel dimensions.

NeuroTrace also performs technical quality checks, including empty segmentation detection, boundary overflow checks, connected-component analysis and signal-to-noise estimation.

I also wanted to avoid a common problem in AI-assisted analysis: reporting evaluation metrics when no reference segmentation exists.

When ground truth is unavailable, metrics such as Dice and IoU are marked as unavailable rather than being fabricated or represented as zero.

4. Gemma 4: An agentic research assistant

This was one of the most interesting parts of the project and a major reason I wanted to participate in the Best Use of Gemma 4 track.

I didn't want to add a chatbot that simply answers generic questions about brain tumors.

Instead, I wanted Gemma 4 to interact with the actual computational workflow.

NeuroTrace uses Gemma 4 through an allowlisted tool architecture.

The agent can interact with validated operations such as:

  • validate_mri_study
  • run_neurosegnet
  • calculate_tumor_volumes
  • inspect_segmentation_quality
  • generate_research_report

The important distinction is that Gemma does not independently calculate or invent the numerical findings.

Python performs the actual measurements. The agent receives structured results and uses them to explain the analysis, answer questions and generate research-oriented summaries.

The integration supports two Gemma 4 model configurations:

  • gemma-4-31b-it
  • gemma-4-26b-a4b-it

It can use the Gemini API when configured with an API key. NeuroTrace also provides a deterministic local synthesis mode when live API access is unavailable.

Another design decision was privacy. Raw MRI volumes remain on the local machine. The hosted AI assistant receives structured metadata and computational results rather than the original MRI voxel data.

This separation between deterministic computation and AI-generated explanation was one of the most important architectural decisions in the project.

5. Research report generation

The final stage brings the analysis together.

NeuroTrace generates downloadable PDF research reports containing:

  • Study metadata.
  • Model and checkpoint information.
  • Quantitative measurements.
  • Technical quality-control findings.
  • Multi-planar visualization snapshots.
  • AI-generated commentary.
  • Research limitations and disclaimers.

The idea is to make the workflow useful beyond the application itself by providing artifacts that researchers can inspect, preserve and share.

The technology behind NeuroTrace

Area Technology
Programming language Python
Deep learning PyTorch, 3D U-Net
MRI processing NiBabel, NumPy
Visualization Plotly, Matplotlib
Web application React 18, Flask
Alternative interface Streamlit
AI assistant Google Gemma 4
PDF generation ReportLab
Configuration and validation Pydantic
Testing Pytest

What I learned

The biggest lesson was that building an AI application is not just about integrating a model or connecting an LLM API.

A useful system needs reliable data handling, well-defined interfaces, meaningful measurements, proper error handling, testing and a clear separation of responsibilities.

I also learned how important it is to constrain AI agents. Giving an LLM access to computational tools is much more useful when those tools have explicit contracts and return verifiable results.

Most importantly, I learned to think beyond model predictions and focus on the complete workflow around them.


Demo

The repository contains the implementation, architecture, documentation, installation instructions and testing workflow.

NeuroTrace provides two ways to explore the application:

  • A React-based web interface with a Flask backend.
  • A classic Streamlit research dashboard.

To run the React/Flask application:

python flask_app.py

To run the Streamlit application:

streamlit run app.py

I recommend adding the following visuals to this section:

  1. A screenshot of the main dashboard.
  2. A screenshot showing the three orthogonal MRI views.
  3. A screenshot of the interactive 3D brain and segmentation.
  4. A screenshot of the Gemma 4 research assistant.
  5. A sample generated PDF report.

A short screen recording demonstrating the complete journey from MRI upload to segmentation, visualization, AI interaction and report generation would make the demo even more useful.


Partner Technologies

Google Gemma 4

Gemma 4 was the central partner technology I wanted to explore.

My goal was to use it as more than a conversational interface.

I integrated it into NeuroTrace as an agentic research assistant that can interact with a controlled set of computational tools.

The architecture separates three responsibilities:

  1. Python: Performs MRI processing, segmentation, numerical measurements and technical quality checks.
  2. Tool layer: Exposes validated operations and structured results to the agent.
  3. Gemma 4: Uses those results to answer research questions, explain findings and generate structured summaries.

This makes the assistant context-aware without allowing it to independently invent measurements.

I also explored different Gemma 4 model configurations for research-oriented reasoning and interactive question answering.

Working with Gemma 4 helped me understand how an LLM can become part of a larger application workflow instead of remaining an isolated chatbot.

The most valuable takeaway was that the quality of an agent depends not only on the model, but also on the tools, context and constraints surrounding it.


Hackathon Experience

On October 31, 2026, I had the opportunity to participate in Hacktoberfest Hack Day Pune × AIDN, organized with the support of MLH and DEV.

It was a wonderful experience to work on an idea I genuinely cared about, turn it into a working implementation and present the engineering decisions behind it.

There were challenges along the way: integrating an existing deep learning model, preserving MRI spatial geometry, building interactive 3D visualizations, designing a reliable tool-based AI assistant and bringing everything together into one coherent application.

But those challenges made the experience even more rewarding.

And the result made the day particularly special.

NeuroTrace won both categories:

  • 🥇 Best Open-Source AI Project
  • 🥇 Best Use of Gemma 4

Winning both categories was something I am genuinely grateful for. Along with the recognition, I was fortunate to receive a $100 cash prize, swags, credits and an Arduino UNO Q board.

A huge thank you to Hacktoberfest, MLH, DEV and AIDN Pune for organizing the event and creating this opportunity.

I am also grateful to the judges and mentors for their time, feedback and encouragement.

And a special thank you to my teammates. The discussions, collaboration and effort throughout the experience made this journey even more memorable.

I am taking away much more than prizes or certificates: new perspectives, practical experience, connections and plenty of motivation to keep building.

This is just the beginning for NeuroTrace.

There is still a lot to improve, test and explore, and I am excited to continue working on it.

If you're interested in computational neuroimaging, open-source AI or agentic applications, I'd love for you to explore the project and share your feedback.

GitHub: https://github.com/AmanPathan24/NeuroTrace

Thank you for reading! 🚀

Images:
Winning Certificate
2D MRI Scan Analysis
3D Visualization


This project is intended strictly for research and educational purposes. It is not a clinical diagnostic system and should not be used to make medical decisions.

來源:DEV Community · dev.to