フィルターのクリア

masking pixel over an image

2 ビュー (過去 30 日間)
sedigheh pagheh
sedigheh pagheh 2022 年 4 月 23 日
コメント済み: SrinivasHarsha 2022 年 4 月 26 日
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.

採用された回答

Image Analyst
Image Analyst 2022 年 4 月 23 日
You forgot to attach 'rill.jpg' and 'Label_1.png'. I'll check back later for them, after you've had a chance to read this:
Are you trying to segment the image into classes? Have you tried the classification learner? Just get your color bands in columns in a table, with each pixel being a row. And have another response variable that has the "true" class that that pixel is. Then start the Classification Learner. Try them all, unless you are sure you want SVM for some reason, then choose only that one.
Or you can use a linear discriminant classifier, or K-Nearest Neighbors, like the attached examples.
  3 件のコメント
Image Analyst
Image Analyst 2022 年 4 月 24 日
Not sure I follow you. Basically the process is this. You have your images, let's say b1, b2, b3, b4 for (say) four different wavelength bands that you're going to consider. And you have an image, say labeledImage, that contains a number depending on what you say that pixel is, like the pixel value is 1 if it's vegetation, 2 for building, 3 for water, etc.. Then you create a table where the pixels are the pixel values
tPredictors = table(b1(:), b2(:), b3(:), b4(:));
Next you make a response variable that is the "ground truth" for each pixel
response = labeledImage(:);
Now you start a new Classification Learner session and you tell it what your predictor variable is and what your response variable is. Hopefully you have R2020a or later because it makes this easier. I think the layout and wording of earlier versions were confusing but it is still possible.
Then you tell it what models you want it to try. Then click the Train button. Then tell it to sort your models by some accuracy metric and click on the button that shows you the confusion matrix.
Now you can export the model to a .mat file, which you can then read in and apply to any new (non-training) data.
SrinivasHarsha
SrinivasHarsha 2022 年 4 月 26 日
Hi Image Analyst,
we need a help from you
can you send a response to my mail if possible.
we will contact you reg: image processing help
my mail id: srinivas.nato@gmail.com

サインインしてコメントする。

その他の回答 (1 件)

sedigheh pagheh
sedigheh pagheh 2022 年 4 月 25 日
thank you so much again. your comment about classification is clear for me and now I do not have a problem with classification.I just have problem with masking pixels of the buildings and vegetation classes. 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.
I am sorry for my question and you are right, it is so confusing and unclear.
  2 件のコメント
Image Analyst
Image Analyst 2022 年 4 月 25 日
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
sedigheh pagheh 2022 年 4 月 25 日
I really grateful for your guidance and replies.
I try more.

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by