masking pixel over an image
Show older comments
Hello friends,
I want to detect rill erosion from an aerial photo in MATLAB. So at first I did classification -- I have 3 soil, vegetation and building classes.
After classification I wanted to masking pixels of the buildings and vegetation classes. Thus I used Image Segmenter, but unfortunately after applying a threshold or local graph cut, I could not get a good result and some pixels of the buildings and vegetations remain in the masked image. I also try to use image region analysier to remove these pixels but in this case I lost some soil pixels related to the rill erosion.
This is my code,
N = imread('rill.jpg');
G = imread('Label_1.PNG');
figure, imshow(G,[]), title('grundt');
%% Form Training
I = double(N);
G_Vec = G(:);
row = size(I, 1);
col = size(I, 2);
bands = size(I, 3);
I_Vec = reshape(I, row*col, bands );
Class1 = I_Vec(G==1, : );
Class1(:,4) = 1;
Class2 = I_Vec(G==2, :);
Class2(:,4) = 2;
Class3 = I_Vec(G==3, :);
Class3(:,4) = 3;
Train_data = cat (1 , Class1, Class2, Class3);
%% SVM Classifier
MdlSVM = fitcecoc(Train_data(:,1:3),Train_data(:,4));
label_Vec= predict(MdlSVM,I_Vec);
label2 = reshape(label_Vec, row , col );
figure, imshow(label2,[]), title('labelsvm');
I thought maybe before the masking I can extract vegetation and soil then apply masking pixel. As I am new in MATLAB, I would be grateful if you help me.
Accepted Answer
More Answers (1)
sedigheh pagheh
on 25 Apr 2022
0 votes
2 Comments
Image Analyst
on 25 Apr 2022
Specifying ground truth is not easily automated. If it were, you'd just do that to segment the things you need. It's because the classical image segmentation algorithms didn't work that you need to try a statistical or deep learning method as an alternative. But you have to have ground truth, and for an image like yours that means tediously labeling each region by hand. Maybe you can get a decent start with some algorithms but you then have to tweak/adjust it to correct for pixels where it got it wrong.
sedigheh pagheh
on 25 Apr 2022
Categories
Find more on Image Segmentation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!