Mahrufa commited on
Commit
c9a761c
Β·
1 Parent(s): 3897321

Update README for BioMedVisionLab

Browse files
Files changed (1) hide show
  1. README.md +223 -336
README.md CHANGED
@@ -11,219 +11,101 @@ license: mit
11
 
12
  # BioMedVisionLab
13
 
14
- **Biomedical Imaging Visualization Toolkit for Retrieval and Super-Resolution**
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
- ```text
190
- data/chest_xray/
191
- train/
192
- NORMAL/
193
- PNEUMONIA/
194
- test/
195
- NORMAL/
196
- PNEUMONIA/
197
- val/
198
- NORMAL/
199
- PNEUMONIA/
200
- ```
201
 
202
- The app also works if only `train/` and `test/` exist.
203
 
204
- Supported image formats:
205
 
206
- - `.jpg`
207
- - `.jpeg`
208
- - `.png`
209
 
210
- ## Setup Commands
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
- Create and activate a virtual environment:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  ```bash
215
- python -m venv venv
 
216
  ```
217
 
 
 
218
  On Windows:
219
 
220
  ```bash
 
221
  venv\Scripts\activate
222
  ```
223
 
224
- On macOS or Linux:
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
- Build the CXR retrieval index with the default generic ResNet18 ImageNet encoder:
237
 
238
  ```bash
239
- python build_index.py --encoder resnet18_imagenet
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  ```
241
 
242
- Build an optional TorchXRayVision DenseNet121 CXR-specific index:
243
 
244
  ```bash
 
 
245
  python build_index.py --encoder torchxrayvision_densenet121
246
  ```
247
 
248
- Indexes are stored separately:
249
 
250
  ```text
251
  embeddings/
@@ -254,172 +154,159 @@ embeddings/
254
  torchxrayvision_densenet121/
255
  ```
256
 
257
- Build the deeper generic ResNet50 ImageNet encoder:
258
 
259
- ```bash
260
- python build_index.py --encoder resnet50_imagenet
 
 
 
 
 
 
 
 
 
261
  ```
262
 
263
- ResNet18 is a lightweight generic natural-image baseline pretrained on ImageNet. ResNet50 is a deeper generic ImageNet baseline with a 2048-dimensional penultimate feature vector. TorchXRayVision DenseNet121 is pretrained for chest X-ray tasks and is included to support research comparisons between generic and CXR-specific visual representations.
 
 
 
 
 
 
 
264
 
265
- Run the dashboard:
266
 
267
  ```bash
268
- python -m streamlit run app.py
 
269
  ```
270
 
271
- If `streamlit` is available on your PATH, this also works:
272
 
273
  ```bash
274
- streamlit run app.py
275
  ```
276
 
277
- ## Deployment on Hugging Face Spaces
278
 
279
- BioMedVisionLab is prepared for Hugging Face Spaces as a Streamlit app. The main entry file is:
280
 
281
- ```text
282
- app.py
283
- ```
284
 
285
- The Streamlit configuration is stored in:
286
 
287
- ```text
288
- .streamlit/config.toml
289
- ```
 
 
 
 
 
290
 
291
- with a `500 MB` upload limit and browser usage-stat collection disabled.
292
 
293
- ### Run Locally
294
 
295
- Install dependencies and start the app:
296
 
297
- ```bash
298
- pip install -r requirements.txt
299
- python -m streamlit run app.py
300
- ```
 
 
 
301
 
302
- Local CXR indexes are optional. If no embeddings are present, the app opens in upload-only mode for query/gallery retrieval, image super-resolution, and contact-map visualization.
303
 
304
- ### Deploy to Hugging Face Spaces
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
- - ResNet18 and ResNet50 are pretrained on natural images, not chest X-rays.
382
- - TorchXRayVision support requires optional dependency installation and a separately built index.
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
- - Retrieval triage is a research dashboard summary, not clinical triage.
387
- - Query-vs-retrieved difference maps are visual comparison aids, not finding maps.
388
- - Folder labels are used only for visualization.
389
- - The intensity heatmap is not Grad-CAM and does not identify pathology.
390
- - Bicubic interpolation is a simple baseline, not a learned super-resolution model.
391
- - Bicubic interpolation may smooth fine detail and cannot recover true missing anatomical structure.
392
- - Synthetic Hi-C contact maps are interface demonstrations only and are not biological results.
393
- - Uploaded Hi-C/contact matrices are visualized as matrix images and are not biologically interpreted.
394
- - PSNR is a basic image-quality metric and does not measure clinical usefulness.
395
- - SSIM is an image-similarity metric and does not measure clinical usefulness.
396
- - The project should not be used for diagnosis, triage, treatment, or clinical decision-making.
397
-
398
- ## CXR Retrieval Research Extension Roadmap
399
-
400
- The Research Extension Roadmap is shown only in the CXR Retrieval tab. The Super-Resolution and Grant Alignment tabs have their own exploration sections instead of repeating the same roadmap.
401
-
402
- - CXR-specific encoders such as TorchXRayVision or medical foundation models
403
- - Grad-CAM visual grounding
404
- - Report-aware retrieval using radiology text
405
- - Microscopy/pathology super-resolution datasets
406
- - Diffusion-based biomedical image enhancement
407
- - Learned super-resolution models such as SRCNN, EDSR, or SwinIR variants
408
- - Metadata-aware retrieval filters
409
- - Hi-C contact map visualization as a future biomedical data visualization extension
410
- - Real Hi-C/Micro-C upload, contact-map retrieval, and omics metadata integration
411
- - Chemical imaging super-resolution with SRS/Raman-style data
412
- - Grant-ready experiment report templates
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
 
414
  ## Disclaimer
415
 
416
- BioMedVisionLab is a research visualization prototype and is not intended for medical diagnosis or clinical decision-making.
 
 
 
 
 
 
417
 
418
- - Retrieval confidence is not diagnostic or clinical confidence.
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
- ## Suggested LinkedIn Project Description
424
 
425
- Built **BioMedVisionLab**, a reusable biomedical visual evaluation workbench in Python and Streamlit. The app includes chest X-ray similarity retrieval using pretrained ResNet18, ResNet50, and optional TorchXRayVision embeddings with cosine similarity, retrieval triage, Top-k sensitivity, query-vs-result comparison, experiment report export, an educational super-resolution demo with MSE, PSNR, SSIM, artifact-risk framing, and a Grant Alignment Lab with a synthetic Hi-C contact-map mini-demo. The project highlights medical image retrieval, chemical imaging super-resolution, explainable AI, and chromatin contact-map visualization concepts for research and portfolio demonstration, not clinical diagnosis or biological interpretation.
 
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
+ ![CXR Retrieval Demo](assets/cxr_retrieval_demo.png)
81
+ ![Super-Resolution Demo](assets/super_resolution_demo.png)
82
+ ![Contact Map Demo](assets/contact_map_demo.png)
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)