Seeking advice on batch processing for opacity masking in ARK(Auto-Refractor Keratometer) retroillumination images (500+ images)

Hello everyone,
I am a graduate student and a relatively new user of MATLAB. I am currently working on a research project involving the analysis of ARK (Auto-Refractor Keratometer) retroillumination images to study cataracts.
I have successfully completed the first step, which is segmenting the pupil ROI (mask) from the anterior segment images using the Segment Anything Model (SAM).
Now, I am facing a challenge: I need to precisely mask the opacities (cloudy areas) within the identified pupil region. While I can perform this task for a single image using SAM, I have a dataset of approximately 500 images, making individual manual processing impractical.
I am looking for guidance on how to automate this process in MATLAB. Specifically:
  1. Are there recommended image processing techniques (e.g., adaptive thresholding, texture analysis, or morphological operations) that work well for identifying cataract opacities within a pupil mask?
  2. Is there a way to batch-process these 500 images efficiently while maintaining high precision?
  3. Are there any existing File Exchange entries or toolboxes you would recommend for this type of medical image segmentation?
I would greatly appreciate any advice, code snippets, or references to help me move forward with my research.
Thank you in advance for your help!
Best regards,

1 Comment

Wanting to find code that will automatically do as you want is an unlikely event, especially if your goal is high precision.
However, YOU ARE A GRAD STUDENT! Grad students work cheaply. Sorry, but that is how grad school works. By the time you find code that does what you want, and then figure out how to use the code written by someone else (very possibly poorly written student code if you can find it for free), test it, and verify that it does work precisely and accurately, you could have done all 500 images as precisely as you can possibly expect. You will be the arbiter of what is a precise result here anyway.
Sorry if it seems a slog, but that will get the job done. And if I must repeat, this is your job. Along the way, you will have learned exactly what it is you need to look for in the task, and you will have learned much about exactly what you need to automate. It has now been a couple of days since you posted the question. You could be done by now. During that time, spend some thought on what you can automate in that process. Break it down into smaller tasks, then solve each task and sub-task.
By way of comparison, when I was solving project Euler problems in MATLAB, one of them asked me to solve around 20 Sudoku puzzles. The idea was to write a Sudoku solving code. But it was easier and far quicker to just solve those 20 puzzles by hand. The same idea arguably applies here. If you don't have code, and you can solve a reasonable problem manually, then just get it done in any way possible. The result is what matters, not how you got to that point in this case.

Sign in to comment.

Answers (2)

Hi,
It is my understanding that you have already segmented the pupil region from ARK retroillumination images using SAM and now need to automate the detection and masking of cataract opacities within those pupil regions across approximately 500 images.
For identifying opacities within the pupil mask, several image processing approaches may be effective depending on the characteristics of your images. Adaptive thresholding techniques can help detect regions with abnormal intensity or contrast compared to the surrounding pupil area, particularly if opacities appear brighter or darker than healthy tissue. Texture analysis using methods such as gray-level co-occurrence matrices (GLCM) or local binary patterns (LBP) can differentiate between smooth and cloudy regions based on spatial intensity variations. Morphological operations like opening, closing, or area filtering can help refine detected regions by removing noise and smoothing boundaries. You may need to experiment with combinations of these techniques on a representative subset of your data to determine which pipeline yields the best results.
For batch processing, you can use imageDatastore to manage your image collection and apply your segmentation pipeline in a loop or using the transform function for efficient processing. If your opacity detection criteria are consistent across images, this approach should scale well to 500 images. Alternatively, if you have access to labeled training data, you could explore training a semantic segmentation network using Deep Learning Toolbox, which may generalize better across variations in image quality and cataract presentation.
I recommend exploring the Image Processing Toolbox documentation for thresholding and morphological functions, and checking MATLAB File Exchange for medical image segmentation examples that may provide useful starting points.
You can refer to the following documentations for more information:
I agree with John. 500 is not that many and you'd spend more time developing an automatic algorithm than if you just hand traced the regions you want. If it took a minute per image, you could knock this out in a few hours.
Deep learning won't work be the approach for you because to train the deep learning model you'll need hundreds of ground truth images where you've labeled the regions in advance. And, well, if you're doing that, you're already done and there is no need to train a model.
I'm attaching my manual tracing demo where you trace regions with a polygon. You could easily modify it to use draw(), drawfreehand, freehand(), or imfreehand to draw continuously instead of roipoly to draw polygons.
I'm attaching some freehand drawing demos for you also.

Categories

Find more on Sudoku in Help Center and File Exchange

Asked:

on 22 Feb 2026

Answered:

on 6 Mar 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!