フィルターのクリア

how to crop image from detected rectangle.?

3 ビュー (過去 30 日間)
Nimisha
Nimisha 2016 年 2 月 16 日
コメント済み: bhagyashri kapre 2019 年 9 月 12 日
clear all;clc
boxImage = imread('IMG.jpg');
boxImage = boxImage(:,:,3);
figure; imshow(boxImage);
title('Image of a Box');
sceneImage = imread('IMG1.jpg');
sceneImage = sceneImage(:,:,3);
figure; imshow(sceneImage);
title('Image of a Cluttered Scene');
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);
figure; imshow(boxImage);
title('100 Strongest Feature Points from Box Image');
hold on;
plot(boxPoints.selectStrongest(100));
figure; imshow(sceneImage);
title('300 Strongest Feature Points from Scene Image');
hold on;
plot(scenePoints.selectStrongest(300));
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure;
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ...
matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');
[tform, inlierBoxPoints, inlierScenePoints] = ...
estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure;
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');
boxPolygon = [1, 1;... % top-left
size(boxImage, 2), 1;... % top-right
size(boxImage, 2), size(boxImage, 1);... % bottom-right
1, size(boxImage, 1);... % bottom-left
1, 1]; % top-left again to close the polygon
newBoxPolygon = transformPointsForward(tform, boxPolygon);
figure; imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');
After ruuning this code, i am able to detect features of one image into another and it draws a rectange at detected portion. Now i want to crop that detected portion and want to save.. How to crop it and save it.?

採用された回答

Image Analyst
Image Analyst 2016 年 2 月 16 日
Have you tried imcrop() and imwrite()?
  6 件のコメント
Sharmin Akhter
Sharmin Akhter 2019 年 2 月 20 日
thanx.. i am also facing the same problem..
bhagyashri kapre
bhagyashri kapre 2019 年 9 月 12 日
xLeft = min(newBoxPolygon(:, 1))
xRight = max(newBoxPolygon(:, 1))
yTop = min(newBoxPolygon(:, 2))
yBottom = max(newBoxPolygon(:, 2))
height = abs(yBottom - yTop)
width = abs(xRight - xLeft);
croppedImage = imcrop(sceneImage, [xLeft, yTop, width, height])
imshow(croppedImage);
Thank you above answer is helful for me in my project

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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