필터 지우기
필터 지우기

How to Crop/Extract a specific location from satellite images using matlab

조회 수: 3 (최근 30일)
meenu v
meenu v 2018년 1월 13일
답변: Image Analyst 2018년 1월 14일
i'm new to MATLAB , i want to extract this part (marked) from the RGB image. please help me

답변 (2개)

Image Analyst
Image Analyst 2018년 1월 14일
Try this:
% Demo to have the user freehand draw an irregular shape over an image, ant then extract a cropped version.
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 = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
imshow(rgbImage, []);
axis on;
title('Original Color Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Ask user to draw freehand mask.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand(); % Actual line of code to do the drawing.
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
xy = hFH.getPosition;
% Now make it smaller so we can show more images.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis on;
drawnow;
title('Original gray scale image', 'FontSize', fontSize);
% Display the freehand mask.
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary mask of the region', 'FontSize', fontSize);
% Now crop the image.
x = xy(:, 1);
y = xy(:, 2);
leftColumn = min(x);
rightColumn = max(x);
topLine = min(y);
bottomLine = max(y);
width = rightColumn - leftColumn + 1;
height = bottomLine - topLine + 1;
croppedImage = imcrop(rgbImage, [leftColumn, topLine, width, height]);
% Display cropped image.
subplot(2, 2, 3);
imshow(croppedImage);
axis on;
title('Cropped image', 'FontSize', fontSize);

Image Analyst
Image Analyst 2018년 1월 13일
Use imfreehand. See attached demo.
  댓글 수: 3
meenu v
meenu v 2018년 1월 14일
Error using iptassert (line 19) Size of I doesn't match size information found in the first input argument.
Error in regionprops>ParseInputs (line 1224) iptassert(isequal(sizeImage,size(I)), ...
Error in regionprops (line 205) [I,requestedStats,officialStats] = ParseInputs(imageSize, argOffset, varargin{:});
Error in Untitled7 (line 66) measurements = regionprops(binaryImage, grayImage, ...
meenu v
meenu v 2018년 1월 14일
plz suggest any way to correct this error.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by