1

I want to crop several Landsat images, of different satellites, in MATLAB employing a shapefile. For only one image, I could manage to do it properly.

But if I try the same with a second image, the matrices associated to the images are of different size, mainly in the black part (zeros) while the mask (white part) in general keeps the same size. Also the location of the mask in both of the images differ within the figure.

All in all, if images have matrices that do not have same number of pixels and the masks are not located in the same part of the figure, it make hard to compare and make operations with them. So I was wondering if there is a way to improve the code above to enable it for cropping several images with different extents using the same shapefile, while keeping the mask in the same location for all of the images as well as the same total number of pixels including the zeros of the black part around the image.

I1 = geotiffinfo('MyImageL8.tif');

[x,y] = pixcenters(I);

[X,Y] = meshgrid(x,y);

roi=shaperead('MyShape.shp');

figure('color','w');

mapshow(roi);

rx=roi.X(1:end-1);

ry=roi.Y(1:end-1);

mask = inpolygon(X,Y,rx,ry);

figure;

imshow(mask);

G1 = imread('MyImageL8.tif');

G2 = imread('MyImageL5.tif');

figure;

imshow(G1);

imshow(G2);

CUT_G1 = im2double(G1).* mask;

CUT_G2 = im2double(G2).* mask;

figure;

subplot(1,2,1)

imshow(CUT_G1);

subplot(1,2,2)

imshow(CUT_G2);

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.