필터 지우기
필터 지우기

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 CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by