フィルターのクリア

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 Center および File ExchangeExplore 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