- 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.
- To overlay this 2D mask to 3D image do the following:
- Invert the mask and replicate it thrice along the channel dimension.
- Set the rest of the area in the image other the ROI as 0.
How to extract out the optic disk after the Watershed transform?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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:
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biomedical Imaging 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!