How to extract out the optic disk after the Watershed transform?

1 回表示 (過去 30 日間)
ZWY
ZWY 2022 年 6 月 15 日
回答済み: VINAYAK LUHA 2023 年 10 月 6 日
Hi, I have found the region of interest (ROI) of the optic disc as shown in first image. Then, I have applied Watershed transform on the ROI image. How can I extract out the optic disc labelled in pink arrow as shown in second image?
Thank you.

回答 (1 件)

VINAYAK LUHA
VINAYAK LUHA 2023 年 10 月 6 日
Hi ZMY,
It is my understanding that you have obtained a segmented mask of the ROI in your image using watershed algorithm and you want a workaround to overlay the mask on the actual image to extract the optic disk.
Follow the below steps for extracting the optic disc after applying the watershed transform:
  1. Obtain a binary mask for the orange region in the image using RGB or HSV-based colour segmentation techniques. Leverage the “MATLAB Color Thresholder App” to ease up this work.
  2. To overlay this 2D mask to 3D image do the following:
  3. Invert the mask and replicate it thrice along the channel dimension.
  4. Set the rest of the area in the image other the ROI as 0.
Refer to the following code snippet to obtain the segmented optic disc:
%Read image and watershed mask
img =imread("img.png");
wsimg=imread("watershed.png");
%Resizing mask to match image dimensions
[w,h,~]=size(img);
wsimg=imresize(wsimg,[w,h]);
%Create binary mask of ROI from the watershed mask using "createMask"
%funciton exported from "Color Thresholder App".
mask =createMask(wsimg);
%invert, replicate and overlay mask on original image
img(repmat(~mask,[1 1 3])) = 0;
imshow(img)
%Binary mask generation code from “MATLAB Colour Thresholder App”
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 03-Oct-2023
%------------------------------------------------------
% Convert RGB image to chosen color space
I = RGB;
% Define thresholds for channel 1 based on histogram settings
channel1Min = 128.000;
channel1Max = 255.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 141.000;
channel2Max = 177.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 0.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
Results
1.Original Image
2.Resized Watershed Image
3.Binary mask of ROI
4.Overlayed mask on image
As a suggestion, since the optic disc spot is bright, you could have achieved the same result relatively easier using the HSV thresholding.
Hope this helps in extracting the optic disc after applying the watershed transform .
Regards,
Vinayak Luha

カテゴリ

Help Center および File ExchangeBiomedical Imaging についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by