How do I complete my matlab code for a given formula.?
์ด์ ๋๊ธ ํ์
% This is done through k-Means clustering and binarization to derive a
% binary classification of each parcel for cropland and non-cropland pixels.
% This process results in 2 clusters per parcel object for which the
% mean values are calculated. Herein, a threshold for pixels higher
% than 0.4 was defined for the derivation of CAF:
% ๐ถ๐ด๐น = ฮฃ๐ > 0 . 4 / ฮฃ๐
% where ฮฃp is the sum of all pixels and ฮฃ๐ > 0 . 4 the sum of pixels
% which are located within the cluster with a mean NDVI higher than 0.4.
% open NDVI file
img = imread('ndvi.tif');
% pickup the shape files of parcels
d = uigetdir(pwd, 'Select a folder');
shapefiles = dir(fullfile(d, '*.shp'));
for m = 1:length(shapefiles)
shapefile = shapefiles(m);
disp(shapefile.name);
S = shaperead(shapefile.name);
polygon = polyshape([S.X], [S.Y]);
% Create a logical mask
logical_mask = inpolygon(lon, lat, polygon.Vertices(:, 1), polygon.Vertices(:, 2));
% Use the logical mask to extract data from ndvi image for parcel
parcel_ndvi = img(logical_mask);
% Apply k-means clustering with k=2
k = 2;
[idx, centroids] = kmeans(parcel_ndvi, k);
X = mean(idx(:,1));
Y = mean(idx(:,2));
end
I would appreciate any help to complete above code as per comments given at the top of this code.
Deve
๋๊ธ ์: 5
Steven Lord
2024๋
3์ 14์ผ
It's not clear to me what help you're looking for. Please ask a specific question about where you're having difficulty and we may be able to provide some guidance about that specific area in your code.
Devendra
2024๋
3์ 14์ผ
ํธ์ง: Walter Roberson
2024๋
3์ 14์ผ
Walter Roberson
2024๋
3์ 14์ผ
You could take
mean(parcel_ndvi(idx == 1))
and compare it to
mean(parcel_ndvi(idx == 2))
to try to decide which cluster is which ?
Walter Roberson
2024๋
3์ 15์ผ
if mean(parcel_ndvi(idx == 1)) > mean(parcel_ndvi(idx == 2))
cropland = 1;
noncropland = 2;
else
cropland = 2;
noncropland = 1;
end
์ฑํ๋ ๋ต๋ณ
์ถ๊ฐ ๋ต๋ณ (0๊ฐ)
์นดํ ๊ณ ๋ฆฌ
๋์๋ง ์ผํฐ ๋ฐ File Exchange์์ Agriculture์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!