Image Segmentation using their magnitude and direction gradients

5 次查看(过去 30 天)
Hello all, i have attacthed magnitude and direction gradients of 3 images. I am trying to achieve a segmentation where the section below the red curve is removed and the section above the red curve should be preserved. I have shown below for image 2:
I have attatched what i want to acheive for image 1 and image 3 as Image-1 and image-3. I used paint to highlight the red curve. Can you guys suggest me some ways to acheive this? Any help is appreciated and thankyou in advance. The code i used is below
clc;
clear;
close all;
a=imread(filename);
B = imgaussfilt(a,1.4);
[Gmag,Gdir]=imgradient(B,'prewitt');
figure;
imshowpair(Gmag,Gdir,'montage');
I have also attacthed the original images as org1, org2 and org3.

回答(1 个)

Image Analyst
Image Analyst 2020-6-7
Just threshold the image and use find() to find the last row in each column where the signal is above the threshold.
thresholdValue = 10; % Whatever works
[rows, columns, numberOfColorChannels] = size(grayImage);
lastRows = zeros(1, columns);
for col = 1 : columns
r = find(grayImage(:, col) > threshold, 1, 'last')
if ~isempty(r)
lastRows(col) = r;
end
end
  1 个评论
Apoorva Maiya
Apoorva Maiya 2020-6-9
Thank you for your help but this methos doesnt seem to work since some rows are empty. Is there anything we could do with the direction gradient because it shows a sharp ridge at whare I want to segment the image.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by