how to generate correct logical mask of the size of shape file?
i am using following code to generate logical mask
function croppedimg = cropimage(data, R, shapefile)
% Load the shapefile and retrieve its info
S = shaperead(shapefile);
% Shapefile projections
info = shapeinfo(shapefile);
crs = info.CoordinateReferenceSystem;
[S.lon,S.lat] = projinv(crs,S.X,S.Y);
% read and reproject image file
p = R.ProjectedCRS;
[x,y] = worldGrid(R);
[lon,lat] = projinv(p,x,y);
% Create a logical mask
% Approach 1: Using ‘inpolygon’ function
xq = lon(:);
yq = lat(:);
in = inpolygon(xq,yq,S.lon,S.lat);
logical_mask = reshape(in,size(lon));
% Debugging: Display the logical mask summary
disp([‘Total number of pixels inside polygon: ‘, num2str(numel(logical_mask))]);
disp([‘Total number of pixels inside image: ‘, num2str(numel(data))]);
However it is showing the
Total number of pixels inside polygon: 16982229
Total number of pixels inside image: 16982229
please suggest me how to create correct logical mask of the size of shape file.
kuldeepi am using following code to generate logical mask
function croppedimg = cropimage(data, R, shapefile)
% Load the shapefile and retrieve its info
S = shaperead(shapefile);
% Shapefile projections
info = shapeinfo(shapefile);
crs = info.CoordinateReferenceSystem;
[S.lon,S.lat] = projinv(crs,S.X,S.Y);
% read and reproject image file
p = R.ProjectedCRS;
[x,y] = worldGrid(R);
[lon,lat] = projinv(p,x,y);
% Create a logical mask
% Approach 1: Using ‘inpolygon’ function
xq = lon(:);
yq = lat(:);
in = inpolygon(xq,yq,S.lon,S.lat);
logical_mask = reshape(in,size(lon));
% Debugging: Display the logical mask summary
disp([‘Total number of pixels inside polygon: ‘, num2str(numel(logical_mask))]);
disp([‘Total number of pixels inside image: ‘, num2str(numel(data))]);
However it is showing the
Total number of pixels inside polygon: 16982229
Total number of pixels inside image: 16982229
please suggest me how to create correct logical mask of the size of shape file.
kuldeep i am using following code to generate logical mask
function croppedimg = cropimage(data, R, shapefile)
% Load the shapefile and retrieve its info
S = shaperead(shapefile);
% Shapefile projections
info = shapeinfo(shapefile);
crs = info.CoordinateReferenceSystem;
[S.lon,S.lat] = projinv(crs,S.X,S.Y);
% read and reproject image file
p = R.ProjectedCRS;
[x,y] = worldGrid(R);
[lon,lat] = projinv(p,x,y);
% Create a logical mask
% Approach 1: Using ‘inpolygon’ function
xq = lon(:);
yq = lat(:);
in = inpolygon(xq,yq,S.lon,S.lat);
logical_mask = reshape(in,size(lon));
% Debugging: Display the logical mask summary
disp([‘Total number of pixels inside polygon: ‘, num2str(numel(logical_mask))]);
disp([‘Total number of pixels inside image: ‘, num2str(numel(data))]);
However it is showing the
Total number of pixels inside polygon: 16982229
Total number of pixels inside image: 16982229
please suggest me how to create correct logical mask of the size of shape file.
kuldeep how to generate correct logical mask ? MATLAB Answers — New Questions