how can I make the dilation and erosion process on the image in the cleanest way?

17 次查看(过去 30 天)
I have uploaded my code file and sample image. In order to get a cleaner segmented image, I need to perform dilation and erosion operations in some steps.
For example, I want to delete values lower than 20 in the substrate img section so that they do not appear. how can I do that operation?
I want to eliminate the lens flare that appears in the middle of the image.
I want the edge borders not to appear in the last segmented image part of the image
  2 个评论
DGM
DGM 2024-3-31,15:08
What is the actual goal? What is the result supposed to be?
For clarity, here's a copy as a plain script with unused outputs commented.
data = imread('00cc2b75cddd.png');
resized_image = imresize(data,[512,512]);
%imshow(resized_image), title 'Resized image';
%RGB to Gray conversion
gray_scale = rgb2gray(resized_image);
%imshow(gray_scale), title 'Gray scale image';
%Contrast enhancement
contrast_enh = imadjust(gray_scale, [0.3, 0.6], []);
% çok uyumlu olmuyosa 0.2 yap
%imshow(contrast_enh), title 'Contrast enhancement'
%Average filtering-blurring
h = fspecial('average',10);
avg_filtered = imfilter(contrast_enh,h);
%imshow(avg_filtered), title 'Average filtering-blurring image';
%Image substraction
img_subs = imsubtract(avg_filtered,contrast_enh);
%imshow(img_subs), title 'Image substraction';
%Finding threshold-binarization
threshold = graythresh(img_subs);
binarize_img = imbinarize(img_subs, threshold);
%imshow(binarize_img), title 'Binarization';
%Noise removal
ortalama_filtre = fspecial('average', 5);
noise_removal = imfilter(binarize_img, ortalama_filtre);
%imshow(noise_removal),title 'Average filtering noise removal';
%Complimenting operation
%comp_img = imcomplement(noise_removal);
%imshow(comp_img), title 'Complimenting operation'
%Image overlaying operation
alpha = 0.5; % Şeffaflık değeri
uint8_img = im2uint8(noise_removal);
blendedImage = alpha * img_subs + (1 - alpha) * uint8_img;
segmented = imadjust(blendedImage, [0.5, 0.7], []);
% seg = comp_img + gray_scale;
% imshow(seg);
imshow(segmented),title 'Segmented image'
Senanur
Senanur 2024-3-31,15:29
my main goal is to do image processing and then deep learning on the visuals. I want the veined structure in the visuals to be clear and obvious, and other roughness to disappear. therefore, I thought that I could achieve this result by performing erosion and dilution operations at some stages.

请先登录,再进行评论。

回答(2 个)

DGM
DGM 2024-4-1,0:49
I'm not sure, but I imagine there are better ways of approaching this type of image. This is just something I came up with by observation.
% in R, the feature contrast is low, but the spot and border contrast is high.
% in G, the feature contrast is high and the spot contrast is low.
inpict = imread('retina.png');
% split the image channels
[R,G,~] = imsplit(inpict);
% get a mask for the black border area
bordermask = imfill(R>30,'holes'); % everything that's not the border
bordermask = ~imerode(bordermask,ones(3));
% get a mask for the edge of the spot
fg = R<220; % everything that's not the spot
fg = bwareafilt(fg,1); % get rid of any specks
spotedges = bwperim(fg); % get the edge regions
spotedges = imdilate(spotedges,ones(3)); % dilate the mask as needed
% get a edge map of G
sigma = 1;
fk = fspecial('log',[1 1]*2*ceil(4*sigma)+1,sigma);
fgedges = imfilter(G,fk,'symmetric');
fgedges = mat2gray(fgedges); % normalize
% get rid of unwanted features
fgedges = fgedges-spotedges-bordermask;
imshow(fgedges)
It's something I guess.
  2 个评论
Senanur
Senanur 2024-4-1,18:12
this answer helped me a lot, thank you very much. i am doing image processing+deep learning for my graduation thesis. Thanks for your help
Image Analyst
Image Analyst 2024-4-1,18:37
Did you also see my answer below? Maybe you didn't like it because it's not what you wanted to hear.
If you just want to find vessels, see this:
By the way while getting my Ph.D. in image processing I worked for over a year on ophthalmic images.

请先登录,再进行评论。


Image Analyst
Image Analyst 2024-4-1,2:47
I don't think you need to do any of that for deep learning.
You don't need to get rid of the black background in the corners. Deep learning will be trained to know that there is nothing there that you care about so it will just ignore those regions by using weights of zero there.
I'm not sure I see lens flare in the image. Does your ophthalmologist say that there is lens flare there? Anyway, deep learning should be able to handle it.
And I don't think you need to adjust contrast because again deep learning should be able to learn with the original pixel values.
And what about morphological operations like dilation and erosion? Well since your network most likely has convolution layers and max pooling layers, this is sort of like erosion and dilation, which are local min and local max respectively, so anything you would do by preprocessing the image is probably not needed since if it were needed then the network would realize that and do it for you as part of the convolution and max pooling.

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by