Azzera filtri
Azzera filtri

how to crop image from detected rectangle.?

3 visualizzazioni (ultimi 30 giorni)
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.?

Risposta accettata

Image Analyst
Image Analyst il 16 Feb 2016
Have you tried imcrop() and imwrite()?
  6 Commenti
Sharmin Akhter
Sharmin Akhter il 20 Feb 2019
thanx.. i am also facing the same problem..
bhagyashri kapre
bhagyashri kapre il 12 Set 2019
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing and Computer Vision in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by