cropping satellite image (RGB image)

1 次查看(过去 30 天)
hy everyone,,, i want to ask a question,, I have some satellite imagery that I downloaded from USGS. I want to doing cropping to the part of that image that unnecessary and take just the areas that I need. I want to ask how to cut the unnecessary part of that image and leaving only the parts that I need? and how to keep cropping I did, have same result for every image? because I need the same cropping area for each image.
can anyone help me? need reply soon.
best regards _trimurti_ God bless you.

回答(2 个)

Walter Roberson
Walter Roberson 2011-9-6
On one of the images, use
[croppedIMG, rect] = imcrop(IMG);
The value stored in to rect will then be the cropping rectangle. You can apply that to another image as an extra argument to imcrop:
croppedIMG2 = imcrop(IMG2, rect);
  5 个评论
UNHAS HASANUDDIN
UNHAS HASANUDDIN 2011-9-10
have code like below, (you can try to run it).
%Change the current folder to the folder of this m-file
%(The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc;%Clear command window
clear;%Delete all variables.
close all;%Close all figure windows except those created by imtool.
imtool close all;%Close all figure windows created by imtool.
workspace;%Make sure the workspace panel is showing.
fontSize=20;
%Read in standad MATLAB color demo images.
imagesFolder='';
if~exist(imagesFolder,'dir')
message=sprintf('Please browse to your image folder');
button=questdlg(message,'Specify Folder','OK','Cancel','OK');
drawnow;%Refresh screen to get rid of dialog box remnants.
if strcmpi(button,'Cancel')
return;
else
imagesFolder=uigetdir();
if imagesFolder==0
return;
end
end
end
%Read the directory to get a list of images.
filePattern=[imagesFolder,'\*.jpg'];
jpegFiles=dir(filePattern);
filePattern = [imagesFolder, '\*.tif'];
tifFiles = dir(filePattern);
filePattern = [imagesFolder, '\*.png'];
pngFiles = dir(filePattern);
filePattern = [imagesFolder, '\*.bmp'];
bmpFiles = dir(filePattern);
imageFiles = [jpegFiles; tifFiles; pngFiles; bmpFiles];
%Bail out if there aren't any images in that folder.
numberOfImagesProcessed = 0;
numberOfImagesToProcess = length(imageFiles);
if numberOfImagesToProcess <= 0
message = sprintf('I did not find any JPG, TIF, PNG, or BMP images
in the folder\n%s\nClick OK to Exit.', imagesFolder);
uiwait(msgbox(message));
return;
end
for k = 1 : numberOfImagesToProcess
%Read this one file.
baseFileName = imageFiles(k).name;
fullFileName = fullfile(imagesFolder, baseFileName);
OriginalImage = imread(fullFileName);
%Cropping Images
[croppedIMG1, rect] = imcrop(OriginalImage);
figure
imshow(croppedIMG1),title('Cropped Image1')
%Prompt user to continue.
promptMessage = sprintf('Currently displaying image #%d of %d:\n%s\n\nDo you want to\nContinue processing, or\nCancel processing?',numberOfImagesProcessed, numberOfImagesToProcess, baseFileName);
button=questdlg(promptMessage, 'Continue?', 'Continue', 'Cancel','Continue');
if strcmp(button, 'Cancel')
break;
end
%Prompt user to continue.
promptMessage = sprintf('Currently displaying image #%d of %d:\n%s\n\nDo you want to\nContinue processing, or\nCancel processing?',numberOfImagesProcessed, numberOfImagesToProcess, baseFileName);
button=questdlg(promptMessage, 'Continue?', 'Continue', 'Cancel','Continue');
if strcmp(button, 'Cancel')
break;
end
end
if numberOfImagesProcessed == 1
caption = sprintf('Done with demo!\n\nProcessed 1 image.\nCheck out the command window for the results');
else
caption = sprintf('Done with demo!\n\nProcessed %d images.\nCheck out the command window for the results', numberOfImagesProcessed);
end
Can you tell me how, when I press the continue button on that program then the next picture in the folder will follow the size of the cropping I did before, (like the function that previously you've given me:
[croppedIMG, rect] = imcrop (IMG);
croppedIMG2 = imcrop (img2, rect);
those functions works on the code below:
img1 = imread ('');
[croppedIMG1, rect] = imcrop (img1);
img2 = imread ('');
croppedIMG2 = imcrop (img2, rect);
% imshow
figure
imshow (croppedIMG1), title ('Cropped image1')
figure
imshow (croppedIMG2), title ('Cropped image2')
my problem now is how to insert the "croppedIMG2 = imcrop (img2, rect); into the first code above, to make subsequent cropping for all images in that folder. Because if i press continue on the program then I have to do the cropping again on the next picture so that the cropping results will be different for each image. It also displayed only cropped image for the first image.
Can you help me?
Walter Roberson
Walter Roberson 2011-9-10
imwrite() the cropped images rather than using save() of the displayed version of the cropped image.

请先登录,再进行评论。


Harry MacDowel
Harry MacDowel 2011-9-7
Unhas,
To save the image in high quality, look for the print function
doc print
You can even set PaperPositionMode. I usually specify a landscape A4, then the resolution.
My sample:-
set(figurehnd,'PaperUnits','centimeters','PaperType','A4','PaperPosition',[0 0 29.7 21.0]);
print(figurehnd,'-djpeg','-r400',g);
figurehnd is the Figure handle variable. -r400 means resolution at 400 dpi.
  1 个评论
Walter Roberson
Walter Roberson 2011-9-7
See also this FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by