Spaces:
Sleeping
Sleeping
Update README for BioMedVisionLab
Browse files
README.md
CHANGED
|
@@ -11,219 +11,101 @@ license: mit
|
|
| 11 |
|
| 12 |
# BioMedVisionLab
|
| 13 |
|
| 14 |
-
**
|
| 15 |
-
|
| 16 |
-
BioMedVisionLab is a polished, professor-facing Streamlit workbench for evaluating biomedical image-like data. It supports visual inspection, embedding comparison, retrieval benchmarking, super-resolution baseline evaluation, future model-output comparison, contact-map visualization, and CSV experiment export.
|
| 17 |
-
|
| 18 |
-
1. Chest X-ray similarity retrieval visualization
|
| 19 |
-
2. Biomedical image super-resolution demo
|
| 20 |
-
3. Grant Alignment Lab for chemical imaging and Hi-C contact-map research directions
|
| 21 |
-
|
| 22 |
-
BioMedVisionLab is upload-first for deployed demonstrations. The app can use a built-in/local CXR embedding index when one is available, but it also works without a local Kaggle dataset by letting users upload biomedical images or contact-map matrices directly in the browser.
|
| 23 |
-
|
| 24 |
-
The project is intended for education, research prototyping, professor-facing demonstrations, and portfolio presentation. It is not intended for medical diagnosis, triage, treatment, or clinical decision-making.
|
| 25 |
-
|
| 26 |
-
## Overview
|
| 27 |
-
|
| 28 |
-
BioMedVisionLab combines representation learning, medical image retrieval, CXR-specific encoder support, batch retrieval quality measurement, super-resolution baseline evaluation, model-output comparison, Hi-C-like matrix visualization, and report export in one interactive dashboard.
|
| 29 |
-
|
| 30 |
-
- `build_index.py` scans a local chest X-ray dataset, extracts embeddings, and saves searchable encoder-specific indexes.
|
| 31 |
-
- `app.py` launches a Streamlit toolkit with tabs for retrieval, super-resolution visualization, and grant-alignment demos.
|
| 32 |
-
|
| 33 |
-
## Motivation
|
| 34 |
-
|
| 35 |
-
Biomedical imaging research often needs visual, explainable tools for understanding what models learn and how image quality affects downstream interpretation. This project focuses on showing model behavior and image-processing concepts without making diagnostic claims.
|
| 36 |
-
|
| 37 |
-
## Module 1: CXR Retrieval
|
| 38 |
-
|
| 39 |
-
The CXR retrieval module visualizes similarity search over a local chest X-ray dataset.
|
| 40 |
-
|
| 41 |
-
Features:
|
| 42 |
-
|
| 43 |
-
- Loads saved embeddings from `embeddings/`
|
| 44 |
-
- Shows a clear **Local CXR index available** or **Upload-only mode** status
|
| 45 |
-
- Supports dataset image queries and uploaded image queries
|
| 46 |
-
- If no saved embeddings are available, supports upload-first retrieval:
|
| 47 |
-
- upload a query image
|
| 48 |
-
- upload a small reference gallery of JPG/PNG/JPEG files
|
| 49 |
-
- build temporary in-session embeddings for the uploaded gallery
|
| 50 |
-
- retrieve visually similar uploaded reference images
|
| 51 |
-
- Uploaded gallery retrieval is temporary and is not saved
|
| 52 |
-
- Uses pretrained torchvision ResNet18 as a lightweight generic ImageNet feature-extraction baseline
|
| 53 |
-
- Adds pretrained torchvision ResNet50 as a deeper generic ImageNet feature-extraction baseline
|
| 54 |
-
- Optionally supports TorchXRayVision DenseNet121 as a CXR-specific embedding encoder when `torchxrayvision` is installed
|
| 55 |
-
- Uses 512-dimensional L2-normalized embeddings for ResNet18, 2048-dimensional L2-normalized embeddings for ResNet50, and DenseNet feature embeddings for TorchXRayVision
|
| 56 |
-
- Stores encoder-specific indexes in `embeddings/resnet18_imagenet/`, `embeddings/resnet50_imagenet/`, and `embeddings/torchxrayvision_densenet121/`
|
| 57 |
-
- Stores metadata for encoder name, embedding dimension, dataset size, build time, and device
|
| 58 |
-
- Lets the app sidebar switch between the generic ImageNet baseline and the CXR-specific encoder when their indexes are available
|
| 59 |
-
- Retrieves top-k visually similar images with cosine similarity
|
| 60 |
-
- Avoids returning the same image as the top result for dataset queries
|
| 61 |
-
- Shows query image, query filename, query label, image resolution, embedding dimension, and query source
|
| 62 |
-
- For uploaded CXR-index queries, runs a transparent input-domain check that looks for CXR-like grayscale, aspect ratio, and contrast properties
|
| 63 |
-
- Flags likely out-of-domain uploads, such as posters or banners, before interpreting CXR nearest-neighbor results
|
| 64 |
-
- Uses colored clinical-style labels for `NORMAL`, `PNEUMONIA`, agreement state, and retrieval confidence
|
| 65 |
-
- Includes a compact model card with encoder, embedding dimension, similarity metric, dataset, and clinical status
|
| 66 |
-
- Adds a clinical-style retrieval triage panel for query source, majority retrieved pattern, agreement, similarity range, and review status
|
| 67 |
-
- Reports retrieval quality metrics for dataset-selected queries:
|
| 68 |
-
- Top-k label agreement count
|
| 69 |
-
- Precision@K
|
| 70 |
-
- Mean cosine similarity
|
| 71 |
-
- Shows Top-k sensitivity for Top-3, Top-5, and Top-10 label agreement when the query label is known
|
| 72 |
-
- Shows a retrieval confidence badge using a simple heuristic based on top similarity and, when available, Precision@K
|
| 73 |
-
- Makes clear that retrieval confidence is not clinical or diagnostic confidence
|
| 74 |
-
- Uses safer uploaded-query wording such as **Top retrieved dataset label** and states that retrieved labels are nearest-neighbor metadata, not predicted labels or diagnoses
|
| 75 |
-
- For out-of-domain uploads, marks retrieval confidence as **Out-of-domain / Low**, hides label agreement metrics as unavailable, and shows NORMAL/PNEUMONIA nearest labels only as debugging context
|
| 76 |
-
- Recommends custom uploaded-gallery retrieval for non-CXR images instead of using the CXR index
|
| 77 |
-
- Renames retrieved examples as a **Similar Case Board**
|
| 78 |
-
- Shows rank, filename, label badge, cosine similarity, query-label agreement, and a progress bar on each result card
|
| 79 |
-
- Includes a compact result table with rank, filename, label, cosine similarity, and label agreement
|
| 80 |
-
- Keeps compact charts for rank-based similarity scores and retrieved-label distribution
|
| 81 |
-
- Adds a query-vs-retrieved comparison view with query image, selected retrieved image, and a simple absolute difference map
|
| 82 |
-
- Adds an **Intensity Heatmap Preview** for the query image
|
| 83 |
-
- Exports the current retrieval experiment as CSV
|
| 84 |
-
- Adds batch retrieval evaluation for 20, 50, or 100 sampled queries
|
| 85 |
-
- Reports Mean Precision@K, label-specific Precision@K, Top-1 match rate, same-label counts, and retrieved-label distributions
|
| 86 |
-
- Exports a batch retrieval benchmark CSV with one row per retrieved result for comparing encoder experiments
|
| 87 |
-
- Adds an Encoder Comparison Benchmark when both indexes exist, using the same sampled queries to compare Mean Precision@K, class Precision@K, and Top-1 match rate
|
| 88 |
-
- Includes the Research Extension Roadmap in the CXR Retrieval tab only, so retrieval users can explore future encoder, explainability, text, microscopy, diffusion, and genomics directions without repeating the roadmap across every tab
|
| 89 |
-
|
| 90 |
-
The intensity heatmap is a simple grayscale intensity visualization. It is not Grad-CAM and does not provide model-based lesion localization.
|
| 91 |
-
The difference map is a visual comparison aid, not a clinical finding map.
|
| 92 |
-
|
| 93 |
-
## Module 2: Super-Resolution Demo
|
| 94 |
-
|
| 95 |
-
The super-resolution module demonstrates the basic image degradation and reconstruction problem.
|
| 96 |
-
|
| 97 |
-
Features:
|
| 98 |
-
|
| 99 |
-
- Select an image from the indexed CXR dataset or upload a biomedical image
|
| 100 |
-
- Works in upload-only deployments when no local CXR index exists
|
| 101 |
-
- Simulate low resolution by downsampling by `2x` or `4x`
|
| 102 |
-
- Reconstruct the image back to original size with bicubic interpolation
|
| 103 |
-
- Display original, simulated low-resolution, and bicubic enhanced images side by side
|
| 104 |
-
- Calculate MSE, PSNR, and SSIM when `scikit-image` is available
|
| 105 |
-
- Compare zoomed center crops of the original, low-resolution, and bicubic enhanced images
|
| 106 |
-
- Use a crop-size slider for quick local inspection
|
| 107 |
-
- Includes a baseline model card for degradation, reconstruction, metrics, and clinical status
|
| 108 |
-
- Adds an artifact risk card explaining that bicubic interpolation can smooth fine structures and cannot recover true missing anatomical detail
|
| 109 |
-
- Provides a large preview selector for original, simulated low-resolution, and bicubic enhanced images
|
| 110 |
-
- Supports uploading a model-enhanced image for comparison against the bicubic baseline
|
| 111 |
-
- Shows bicubic vs original and uploaded-output vs original metrics in a comparison table
|
| 112 |
-
- Adds batch super-resolution evaluation for 20, 50, or 100 indexed images
|
| 113 |
-
- Exports batch super-resolution benchmark CSV files for method comparison
|
| 114 |
-
- Exports the current super-resolution experiment as CSV
|
| 115 |
-
- Explains the relevance of throughput/resolution tradeoffs, microscopy/pathology, and future diffusion-based enhancement
|
| 116 |
-
- Adds a **Super-Resolution Exploration Studio** with prompts for uploaded learned outputs, crop-level inspection, metric deltas, and artifact checks
|
| 117 |
-
|
| 118 |
-
This module is a lightweight educational prototype. Bicubic super-resolution is an educational baseline, not a trained AI model or a clinical enhancement method.
|
| 119 |
-
|
| 120 |
-
## Module 3: Grant Alignment Lab
|
| 121 |
-
|
| 122 |
-
The Grant Alignment Lab frames BioMedVisionLab as a reusable visual evaluation workbench for biomedical imaging and multimodal biology research.
|
| 123 |
-
|
| 124 |
-
Features:
|
| 125 |
-
|
| 126 |
-
- Chemical Imaging Super-Resolution alignment card:
|
| 127 |
-
- low-resolution biomedical/chemical imaging challenge
|
| 128 |
-
- current support for degradation simulation, bicubic baseline, PSNR, SSIM, MSE, crop inspection, and artifact warnings
|
| 129 |
-
- future diffusion-based super-resolution, microscopy/pathology datasets, and SRS/Raman-style image support
|
| 130 |
-
- Hi-C Contact Map Visualization alignment card:
|
| 131 |
-
- sparse, noisy, high-dimensional image-like contact matrices
|
| 132 |
-
- current support for matrix visualization and resolution-enhancement concepts
|
| 133 |
-
- future real Hi-C/Micro-C upload, contact-map retrieval, and RNA-seq/ATAC-seq metadata integration
|
| 134 |
-
- Synthetic Hi-C contact map mini-demo:
|
| 135 |
-
- generates synthetic contact matrices with diagonal structure and loop-like bright spots
|
| 136 |
-
- simulates low-resolution contact maps and bicubic upscaling
|
| 137 |
-
- displays original, low-resolution, upscaled, and absolute difference maps
|
| 138 |
-
- reports Matrix MSE, Matrix PSNR, and optional Matrix SSIM
|
| 139 |
-
- exports the synthetic Hi-C demo report as CSV
|
| 140 |
-
- Upload support for `.npy` or `.csv` square contact matrices:
|
| 141 |
-
- validates square matrices
|
| 142 |
-
- safely normalizes values
|
| 143 |
-
- displays uploaded contact map, simulated low-resolution map, bicubic-upscaled map, and difference map
|
| 144 |
-
- exports Hi-C matrix evaluation metrics as CSV
|
| 145 |
-
- Adds a **Multimodal Exploration Hub** for matrix uploads, low/high-resolution matrix comparison, diagonal profiles, and future metadata links
|
| 146 |
-
|
| 147 |
-
The deployed app can therefore demonstrate radiology image retrieval, biomedical super-resolution baselines, and contact-map matrix visualization without requiring users to download the repository or install the original local dataset.
|
| 148 |
-
|
| 149 |
-
Synthetic contact maps are used only to demonstrate the visualization interface. They are not biological results.
|
| 150 |
-
Uploaded contact maps are visualized as matrix images. This prototype does not yet perform biological feature calling.
|
| 151 |
-
|
| 152 |
-
## Biomedical Imaging Relevance
|
| 153 |
-
|
| 154 |
-
BioMedVisionLab connects to common biomedical imaging research workflows:
|
| 155 |
-
|
| 156 |
-
- Chest X-ray dataset exploration
|
| 157 |
-
- Visual search and content-based medical image retrieval
|
| 158 |
-
- Representation learning with pretrained vision models
|
| 159 |
-
- Retrieval confidence and uncertainty-style summaries for visual search behavior
|
| 160 |
-
- Clinical-style retrieval triage and Top-k sensitivity checks for research review
|
| 161 |
-
- Comparing generic ImageNet embeddings with CXR-specific embeddings
|
| 162 |
-
- Batch measurement of retrieval quality across repeated query samples
|
| 163 |
-
- Query-vs-retrieved visual comparison with a non-clinical difference map
|
| 164 |
-
- Explainable AI previews and future Grad-CAM visual grounding
|
| 165 |
-
- Image degradation and reconstruction experiments
|
| 166 |
-
- Super-resolution metrics for biomedical imaging baselines
|
| 167 |
-
- Artifact-risk framing for educational super-resolution baselines
|
| 168 |
-
- Comparing future learned or diffusion-based super-resolution outputs against bicubic interpolation
|
| 169 |
-
- Chemical imaging super-resolution grant prototypes
|
| 170 |
-
- Chromatin contact-map visualization and retrieval concepts
|
| 171 |
-
- Multimodal biology workbench patterns for image-like matrices and metadata
|
| 172 |
-
- Educational demonstrations for biomedical AI portfolios
|
| 173 |
-
- Conceptual links to microscopy and pathology super-resolution
|
| 174 |
-
|
| 175 |
-
## Connection to Core Concepts
|
| 176 |
-
|
| 177 |
-
**Representation learning:** ResNet18, ResNet50, or TorchXRayVision converts images into numerical embeddings that summarize visual patterns.
|
| 178 |
-
|
| 179 |
-
**Image retrieval:** Cosine similarity compares embeddings and ranks images by visual resemblance.
|
| 180 |
-
|
| 181 |
-
**Explainable AI:** The dashboard includes a simple intensity heatmap preview as a non-diagnostic visualization placeholder. Future work can add Grad-CAM or other model-based visual grounding.
|
| 182 |
-
|
| 183 |
-
**Super-resolution:** The demo degrades an image and reconstructs it, illustrating why high-resolution structure matters in biomedical imaging.
|
| 184 |
-
|
| 185 |
-
## Dataset Instructions
|
| 186 |
-
|
| 187 |
-
Place a small public chest X-ray dataset inside:
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
test/
|
| 195 |
-
NORMAL/
|
| 196 |
-
PNEUMONIA/
|
| 197 |
-
val/
|
| 198 |
-
NORMAL/
|
| 199 |
-
PNEUMONIA/
|
| 200 |
-
```
|
| 201 |
|
| 202 |
-
|
| 203 |
|
| 204 |
-
|
| 205 |
|
| 206 |
-
|
| 207 |
-
- `.jpeg`
|
| 208 |
-
- `.png`
|
| 209 |
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
```bash
|
| 215 |
-
|
|
|
|
| 216 |
```
|
| 217 |
|
|
|
|
|
|
|
| 218 |
On Windows:
|
| 219 |
|
| 220 |
```bash
|
|
|
|
| 221 |
venv\Scripts\activate
|
| 222 |
```
|
| 223 |
|
| 224 |
-
On macOS
|
| 225 |
|
| 226 |
```bash
|
|
|
|
| 227 |
source venv/bin/activate
|
| 228 |
```
|
| 229 |
|
|
@@ -233,19 +115,37 @@ Install dependencies:
|
|
| 233 |
pip install -r requirements.txt
|
| 234 |
```
|
| 235 |
|
| 236 |
-
|
| 237 |
|
| 238 |
```bash
|
| 239 |
-
python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
```
|
| 241 |
|
| 242 |
-
|
| 243 |
|
| 244 |
```bash
|
|
|
|
|
|
|
| 245 |
python build_index.py --encoder torchxrayvision_densenet121
|
| 246 |
```
|
| 247 |
|
| 248 |
-
|
| 249 |
|
| 250 |
```text
|
| 251 |
embeddings/
|
|
@@ -254,172 +154,159 @@ embeddings/
|
|
| 254 |
torchxrayvision_densenet121/
|
| 255 |
```
|
| 256 |
|
| 257 |
-
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
```
|
| 262 |
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
-
|
| 266 |
|
| 267 |
```bash
|
| 268 |
-
|
|
|
|
| 269 |
```
|
| 270 |
|
| 271 |
-
If
|
| 272 |
|
| 273 |
```bash
|
| 274 |
-
|
| 275 |
```
|
| 276 |
|
| 277 |
-
|
| 278 |
|
| 279 |
-
|
| 280 |
|
| 281 |
-
|
| 282 |
-
app.py
|
| 283 |
-
```
|
| 284 |
|
| 285 |
-
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
-
|
| 292 |
|
| 293 |
-
##
|
| 294 |
|
| 295 |
-
|
| 296 |
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
-
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
1. Create a new Hugging Face Space.
|
| 307 |
-
2. Select **Streamlit** as the Space SDK.
|
| 308 |
-
3. Upload or push the repository files, including:
|
| 309 |
-
- `app.py`
|
| 310 |
-
- `requirements.txt`
|
| 311 |
-
- `.streamlit/config.toml`
|
| 312 |
-
- `README.md`
|
| 313 |
-
4. Spaces will install dependencies from `requirements.txt` and run the Streamlit app from `app.py`.
|
| 314 |
-
5. Optional local embedding folders can be added under `embeddings/`, but deployed demos can also run without them through upload-first workflows.
|
| 315 |
-
|
| 316 |
-
### Deployment Limitations
|
| 317 |
-
|
| 318 |
-
- Uploaded files are temporary and are not saved as a persistent dataset.
|
| 319 |
-
- Large datasets should be uploaded as smaller representative samples.
|
| 320 |
-
- The app is not for diagnosis, triage, treatment, or clinical decision-making.
|
| 321 |
-
- Heavy diffusion-model training or large-scale model inference is not supported in this demo.
|
| 322 |
-
- If TorchXRayVision is unavailable, uploaded-image embedding falls back to ResNet18 and the app shows a warning.
|
| 323 |
-
- If `cooler` is unavailable, `.cool` and `.mcool` upload is disabled with a helpful message; `.csv` and `.npy` contact matrices still work.
|
| 324 |
-
|
| 325 |
-
## Method Details
|
| 326 |
-
|
| 327 |
-
For CXR retrieval, each image is:
|
| 328 |
-
|
| 329 |
-
1. Converted to RGB
|
| 330 |
-
2. Resized to `224x224`
|
| 331 |
-
3. Normalized with ImageNet mean and standard deviation
|
| 332 |
-
4. Passed through pretrained ResNet18 with the classifier removed
|
| 333 |
-
5. Converted into a 512-dimensional embedding
|
| 334 |
-
6. L2-normalized for cosine similarity search
|
| 335 |
-
7. Compared with indexed embeddings using cosine similarity
|
| 336 |
-
8. Summarized with rank-based similarity, label agreement, Precision@K, and mean similarity
|
| 337 |
-
9. Reviewed with model-card metadata, retrieval triage, Top-k sensitivity, and optional visual comparison
|
| 338 |
-
10. Exported as a CSV experiment report
|
| 339 |
-
|
| 340 |
-
Batch retrieval evaluation samples labeled dataset queries, retrieves Top-k neighbors while excluding the query image, and exports one row per retrieved result. This makes CSV exports useful for comparing generic and CXR-specific encoders.
|
| 341 |
-
|
| 342 |
-
Retrieval confidence is a heuristic:
|
| 343 |
-
|
| 344 |
-
- High confidence for dataset queries if top similarity is at least `0.90` and Precision@K is at least `0.80`
|
| 345 |
-
- Medium confidence if top similarity is at least `0.80`
|
| 346 |
-
- Low confidence otherwise
|
| 347 |
-
- Uploaded images use top similarity only because query-label agreement is unavailable
|
| 348 |
-
|
| 349 |
-
Uploaded CXR-index queries also run a simple out-of-domain input check before retrieval summaries are shown. The check uses transparent image heuristics only:
|
| 350 |
-
|
| 351 |
-
- whether the image is mostly grayscale
|
| 352 |
-
- whether the aspect ratio is roughly radiograph-like
|
| 353 |
-
- whether the image is highly colorful
|
| 354 |
-
- whether grayscale contrast is sufficient for a medical-image-like input
|
| 355 |
-
|
| 356 |
-
This check is not a clinical classifier. If an uploaded image appears out of domain, the app still allows nearest-neighbor retrieval but warns that results may be meaningless and displays nearest CXR dataset labels only as debugging metadata.
|
| 357 |
-
|
| 358 |
-
For super-resolution, each image is:
|
| 359 |
-
|
| 360 |
-
1. Converted safely to RGB
|
| 361 |
-
2. Downsampled by `2x` or `4x`
|
| 362 |
-
3. Reconstructed to original size using bicubic interpolation
|
| 363 |
-
4. Compared against the original image using MSE, PSNR, and optional SSIM
|
| 364 |
-
5. Displayed with center-crop comparisons for local detail inspection
|
| 365 |
-
6. Reviewed with artifact-risk and baseline-method cards
|
| 366 |
-
7. Exported as a CSV experiment report
|
| 367 |
-
|
| 368 |
-
ChemDiffuse-style comparison allows an externally generated enhanced image to be uploaded and compared against the original image and bicubic baseline using PSNR, SSIM, and MSE.
|
| 369 |
-
|
| 370 |
-
For the synthetic Hi-C mini-demo:
|
| 371 |
-
|
| 372 |
-
1. A synthetic square contact matrix is generated with diagonal structure and loop-like bright spots.
|
| 373 |
-
2. Noise is added using the dashboard slider.
|
| 374 |
-
3. The matrix is downsampled by `2x` or `4x`.
|
| 375 |
-
4. The low-resolution matrix is bicubic-upscaled to the original matrix size.
|
| 376 |
-
5. Matrix MSE, Matrix PSNR, and optional Matrix SSIM are reported.
|
| 377 |
-
6. The demo can be exported as a CSV report.
|
| 378 |
|
| 379 |
## Limitations
|
| 380 |
|
| 381 |
-
-
|
| 382 |
-
-
|
| 383 |
-
- Retrieval results show visual similarity, not clinical equivalence.
|
| 384 |
-
- The CXR retrieval module is intended for chest X-ray-like inputs. Out-of-domain images may still produce nearest-neighbor results, but these are not meaningful and are flagged by the app.
|
| 385 |
- Retrieval confidence is not clinical confidence.
|
| 386 |
-
-
|
| 387 |
-
-
|
| 388 |
-
-
|
| 389 |
-
-
|
| 390 |
-
-
|
| 391 |
-
|
| 392 |
-
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
-
|
| 403 |
-
-
|
| 404 |
-
-
|
| 405 |
-
|
| 406 |
-
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
-
|
| 411 |
-
-
|
| 412 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
## Disclaimer
|
| 415 |
|
| 416 |
-
BioMedVisionLab is a research visualization prototype
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
-
|
| 419 |
-
- The intensity heatmap preview is not Grad-CAM.
|
| 420 |
-
- Bicubic super-resolution is an educational baseline, not a trained AI model.
|
| 421 |
-
- Synthetic Hi-C contact maps are not biological results.
|
| 422 |
|
| 423 |
-
|
| 424 |
|
| 425 |
-
|
|
|
|
| 11 |
|
| 12 |
# BioMedVisionLab
|
| 13 |
|
| 14 |
+
**A deployable biomedical visual evaluation workbench for image retrieval, super-resolution evaluation, and contact-map visualization.**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
BioMedVisionLab is a research prototype for inspecting biomedical image-like data through an interactive dashboard. It supports chest X-ray retrieval benchmarking, super-resolution baseline/model-output comparison, and Hi-C/contact-map visualization.
|
| 17 |
+
|
| 18 |
+
The goal is **not diagnosis**. The goal is **visual evaluation**: helping researchers inspect model behavior, compare enhancement outputs, identify failure cases, and export experiment summaries.
|
| 19 |
+
|
| 20 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
## Live Demo
|
| 23 |
|
| 24 |
+
Try the deployed app here:
|
| 25 |
|
| 26 |
+
**https://huggingface.co/spaces/Mahrufa/BioMedVisionLab**
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
Hosted demo mode is intended for small uploaded samples. Large datasets, full benchmarks, and GPU-heavy workflows should be tested locally or on suitable research infrastructure.
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Why This Project Matters
|
| 33 |
+
|
| 34 |
+
Biomedical AI models often produce embeddings, enhanced images, or reconstructed matrices, but researchers still need clear ways to inspect whether those outputs are meaningful.
|
| 35 |
+
|
| 36 |
+
BioMedVisionLab helps with:
|
| 37 |
+
|
| 38 |
+
- **Inspecting retrieval behavior** instead of only looking at final numbers.
|
| 39 |
+
- **Comparing baseline vs model-enhanced biomedical images** with visual and quantitative metrics.
|
| 40 |
+
- **Visualizing image-like biological matrices**, such as Hi-C/contact maps, for resolution-style analysis.
|
| 41 |
+
|
| 42 |
+
BioMedVisionLab is designed as a reusable visual evaluation workbench for biomedical image-like data, including radiology images, microscopy/chemical imaging outputs, pathology-style images, and genomic contact maps.
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## Core Modules
|
| 47 |
+
|
| 48 |
+
| Module | What it does | Research value |
|
| 49 |
+
|---|---|---|
|
| 50 |
+
| **CXR Retrieval** | Retrieves visually similar chest X-rays using encoder embeddings. | Compares generic vs CXR-specific visual representations. |
|
| 51 |
+
| **Super-Resolution Demo** | Simulates low-resolution images, reconstructs them with bicubic interpolation, and compares metrics. | Provides a transparent baseline for biomedical image enhancement workflows. |
|
| 52 |
+
| **Grant Alignment Lab** | Visualizes synthetic or uploaded contact maps and compares low-resolution vs upscaled matrices. | Bridges the dashboard toward Hi-C/chromatin contact-map analysis. |
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
|
| 56 |
+
## Key Features
|
| 57 |
+
|
| 58 |
+
- Upload-first demo mode for biomedical images and contact maps.
|
| 59 |
+
- Chest X-ray retrieval using encoder embeddings.
|
| 60 |
+
- Encoder comparison support for:
|
| 61 |
+
- ResNet18 ImageNet baseline
|
| 62 |
+
- ResNet50 ImageNet baseline
|
| 63 |
+
- TorchXRayVision DenseNet121 CXR encoder
|
| 64 |
+
- Retrieval metrics including Precision@K, Top-1 match, label distribution, and mean cosine similarity.
|
| 65 |
+
- Out-of-domain warning for non-CXR uploads.
|
| 66 |
+
- Super-resolution baseline evaluation using PSNR, SSIM, and MSE.
|
| 67 |
+
- Optional upload of model-enhanced images for comparison against bicubic baseline.
|
| 68 |
+
- Synthetic and uploaded contact-map visualization using CSV/NPY inputs.
|
| 69 |
+
- Hi-C/contact-map metrics including matrix PSNR, SSIM, MSE, and difference maps.
|
| 70 |
+
- CSV exports for experiment tracking and method comparison.
|
| 71 |
+
- Docker-based deployment on Hugging Face Spaces.
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
## Screenshots
|
| 76 |
+
|
| 77 |
+
Add screenshots or GIFs here after deployment.
|
| 78 |
+
|
| 79 |
+
```md
|
| 80 |
+

|
| 81 |
+

|
| 82 |
+

|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## Quick Start
|
| 88 |
+
|
| 89 |
+
Clone the repository:
|
| 90 |
|
| 91 |
```bash
|
| 92 |
+
git clone https://github.com/mahrufa-binta-ali/BioMedVisionLab.git
|
| 93 |
+
cd BioMedVisionLab
|
| 94 |
```
|
| 95 |
|
| 96 |
+
Create and activate a virtual environment.
|
| 97 |
+
|
| 98 |
On Windows:
|
| 99 |
|
| 100 |
```bash
|
| 101 |
+
python -m venv venv
|
| 102 |
venv\Scripts\activate
|
| 103 |
```
|
| 104 |
|
| 105 |
+
On macOS/Linux:
|
| 106 |
|
| 107 |
```bash
|
| 108 |
+
python -m venv venv
|
| 109 |
source venv/bin/activate
|
| 110 |
```
|
| 111 |
|
|
|
|
| 115 |
pip install -r requirements.txt
|
| 116 |
```
|
| 117 |
|
| 118 |
+
Run the app:
|
| 119 |
|
| 120 |
```bash
|
| 121 |
+
python -m streamlit run app.py
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## Optional: Build a Local CXR Index
|
| 127 |
+
|
| 128 |
+
The deployed demo can run in upload-first mode. For local CXR retrieval benchmarking, place a chest X-ray dataset under:
|
| 129 |
+
|
| 130 |
+
```text
|
| 131 |
+
data/chest_xray/
|
| 132 |
+
train/
|
| 133 |
+
NORMAL/
|
| 134 |
+
PNEUMONIA/
|
| 135 |
+
test/
|
| 136 |
+
NORMAL/
|
| 137 |
+
PNEUMONIA/
|
| 138 |
```
|
| 139 |
|
| 140 |
+
Then build embeddings for one or more encoders:
|
| 141 |
|
| 142 |
```bash
|
| 143 |
+
python build_index.py --encoder resnet18_imagenet
|
| 144 |
+
python build_index.py --encoder resnet50_imagenet
|
| 145 |
python build_index.py --encoder torchxrayvision_densenet121
|
| 146 |
```
|
| 147 |
|
| 148 |
+
Embeddings are saved under:
|
| 149 |
|
| 150 |
```text
|
| 151 |
embeddings/
|
|
|
|
| 154 |
torchxrayvision_densenet121/
|
| 155 |
```
|
| 156 |
|
| 157 |
+
Large datasets and embedding files are intentionally excluded from Git.
|
| 158 |
|
| 159 |
+
---
|
| 160 |
+
|
| 161 |
+
## Deployment
|
| 162 |
+
|
| 163 |
+
This project is deployed using **Docker on Hugging Face Spaces**.
|
| 164 |
+
|
| 165 |
+
The Space uses:
|
| 166 |
+
|
| 167 |
+
```yaml
|
| 168 |
+
sdk: docker
|
| 169 |
+
app_port: 7860
|
| 170 |
```
|
| 171 |
|
| 172 |
+
The Dockerfile runs the Streamlit app on port `7860`.
|
| 173 |
+
|
| 174 |
+
To deploy manually:
|
| 175 |
+
|
| 176 |
+
1. Create a new Hugging Face Space.
|
| 177 |
+
2. Select **Docker** as the SDK.
|
| 178 |
+
3. Push this repository to the Space.
|
| 179 |
+
4. Hugging Face will build the Docker image and launch the app.
|
| 180 |
|
| 181 |
+
Example push command:
|
| 182 |
|
| 183 |
```bash
|
| 184 |
+
git remote add space https://huggingface.co/spaces/Mahrufa/BioMedVisionLab
|
| 185 |
+
git push space main
|
| 186 |
```
|
| 187 |
|
| 188 |
+
If the Space already has an initial commit and rejects the push, use:
|
| 189 |
|
| 190 |
```bash
|
| 191 |
+
git push space main --force
|
| 192 |
```
|
| 193 |
|
| 194 |
+
---
|
| 195 |
|
| 196 |
+
## CSV Reports
|
| 197 |
|
| 198 |
+
BioMedVisionLab supports CSV exports for experiment tracking.
|
|
|
|
|
|
|
| 199 |
|
| 200 |
+
Single reports describe the current selected example. Batch benchmark reports export many rows and are intended for method comparison.
|
| 201 |
|
| 202 |
+
| Report | Purpose |
|
| 203 |
+
|---|---|
|
| 204 |
+
| Single-query retrieval report | Inspect one query and its retrieved cases. |
|
| 205 |
+
| Batch retrieval benchmark | Compare retrieval quality over many query images. |
|
| 206 |
+
| Batch retrieval summary | Summarize Precision@K, Top-1 match, and class-level retrieval behavior. |
|
| 207 |
+
| Single-image SR report | Record PSNR, SSIM, and MSE for one image. |
|
| 208 |
+
| Batch SR benchmark | Evaluate reconstruction metrics over many images. |
|
| 209 |
+
| Hi-C matrix evaluation report | Record contact-map enhancement metrics for a matrix experiment. |
|
| 210 |
|
| 211 |
+
---
|
| 212 |
|
| 213 |
+
## Intended Use
|
| 214 |
|
| 215 |
+
BioMedVisionLab is intended for:
|
| 216 |
|
| 217 |
+
- Research prototyping
|
| 218 |
+
- Visual model evaluation
|
| 219 |
+
- Biomedical image-like data inspection
|
| 220 |
+
- Retrieval benchmarking
|
| 221 |
+
- Super-resolution baseline comparison
|
| 222 |
+
- Contact-map visualization experiments
|
| 223 |
+
- Teaching and portfolio demonstration
|
| 224 |
|
| 225 |
+
It is **not** intended for clinical diagnosis, patient-facing use, or medical decision-making.
|
| 226 |
|
| 227 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
## Limitations
|
| 230 |
|
| 231 |
+
- This is a research prototype, not a diagnostic system.
|
| 232 |
+
- Retrieval labels come from nearest dataset examples and should not be interpreted as predictions.
|
|
|
|
|
|
|
| 233 |
- Retrieval confidence is not clinical confidence.
|
| 234 |
+
- Bicubic super-resolution is a transparent baseline, not a trained AI enhancement model.
|
| 235 |
+
- Synthetic Hi-C/contact maps are interface demonstrations, not biological results.
|
| 236 |
+
- Uploaded files in hosted demo mode are processed temporarily during the session.
|
| 237 |
+
- Large biomedical datasets may require local execution or GPU-backed infrastructure.
|
| 238 |
+
- The current hosted demo is designed for small samples, not full-scale clinical or genomics pipelines.
|
| 239 |
+
|
| 240 |
+
---
|
| 241 |
+
|
| 242 |
+
## Research Roadmap
|
| 243 |
+
|
| 244 |
+
Planned extensions include:
|
| 245 |
+
|
| 246 |
+
- CXR-specific foundation-model encoders.
|
| 247 |
+
- Grad-CAM or model-based visual grounding.
|
| 248 |
+
- Report-aware CXR retrieval using radiology text.
|
| 249 |
+
- Microscopy/pathology super-resolution benchmarks.
|
| 250 |
+
- Diffusion-based biomedical image enhancement comparison.
|
| 251 |
+
- Real `.cool` / `.mcool` Hi-C contact-map support.
|
| 252 |
+
- Batch evaluation dashboards for multiple models and datasets.
|
| 253 |
+
|
| 254 |
+
---
|
| 255 |
+
|
| 256 |
+
## Tech Stack
|
| 257 |
+
|
| 258 |
+
- Python
|
| 259 |
+
- Streamlit
|
| 260 |
+
- PyTorch
|
| 261 |
+
- torchvision
|
| 262 |
+
- TorchXRayVision
|
| 263 |
+
- NumPy
|
| 264 |
+
- pandas
|
| 265 |
+
- scikit-image
|
| 266 |
+
- Altair
|
| 267 |
+
- Docker
|
| 268 |
+
- Hugging Face Spaces
|
| 269 |
+
|
| 270 |
+
---
|
| 271 |
+
|
| 272 |
+
## Project Structure
|
| 273 |
+
|
| 274 |
+
```text
|
| 275 |
+
BioMedVisionLab/
|
| 276 |
+
β
|
| 277 |
+
βββ app.py
|
| 278 |
+
βββ build_index.py
|
| 279 |
+
βββ requirements.txt
|
| 280 |
+
βββ Dockerfile
|
| 281 |
+
βββ README.md
|
| 282 |
+
βββ .gitignore
|
| 283 |
+
β
|
| 284 |
+
βββ .streamlit/
|
| 285 |
+
β βββ config.toml
|
| 286 |
+
β
|
| 287 |
+
βββ docs/
|
| 288 |
+
β βββ TECHNICAL_NOTES.md
|
| 289 |
+
β βββ ROADMAP.md
|
| 290 |
+
β
|
| 291 |
+
βββ data/ # ignored by Git
|
| 292 |
+
βββ embeddings/ # ignored by Git
|
| 293 |
+
βββ assets/ # optional screenshots/GIFs
|
| 294 |
+
```
|
| 295 |
+
|
| 296 |
+
---
|
| 297 |
|
| 298 |
## Disclaimer
|
| 299 |
|
| 300 |
+
BioMedVisionLab is a research visualization prototype. It is not approved for clinical use and should not be used for diagnosis, treatment planning, or medical decision-making.
|
| 301 |
+
|
| 302 |
+
Uploaded images are not classified by the app. Labels shown in retrieval modules come from nearest reference examples and are only used for visualization and evaluation.
|
| 303 |
+
|
| 304 |
+
---
|
| 305 |
+
|
| 306 |
+
## Author
|
| 307 |
|
| 308 |
+
**Mahrufa Binta Ali**
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
+
GitHub: [mahrufa-binta-ali](https://github.com/mahrufa-binta-ali)
|
| 311 |
|
| 312 |
+
Project: [BioMedVisionLab](https://github.com/mahrufa-binta-ali/BioMedVisionLab)
|