이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to work in a specific area in an image ?
조회 수: 5 (최근 30일)
이전 댓글 표시
After using the object detection technique (https://fr.mathworks.com/help/vision/examples/object-detection-in-a-cluttered-scene-using-point-feature-matching.html) and after i found the desired object in image and drew the rectangle. How can i start working inside the rectangle, for example to draw the contour of the object inside the green rectanle? I am new to the image processing tools and to matlab
채택된 답변
Ameer Hamza
2018년 5월 2일
편집: Ameer Hamza
2018년 5월 2일
smallImage = imcrop(originalImage, rectangle);
댓글 수: 23
Theodor Al Saify
2018년 5월 2일
The problem is i don't have a rectangle, i have a line that was drawen. if i try smallImage = imcrop(originalImage, line); i get an error.
Ameer Hamza
2018년 5월 2일
"i found the desired object in image and drew the rectangle"
How did you draw the rectangle?
Ameer Hamza
2018년 5월 2일
Still, if you have two edges of the line, you can construct a rectangle. Can you show, what are the values you used to draw the line?
Image Analyst
2018년 5월 2일
Use the rows and columns:
smallImage = originalImage(row1:row2, column1:column2, :);
Theodor Al Saify
2018년 5월 2일
편집: Theodor Al Saify
2018년 5월 2일

This is the code that i used to draw the rectangle it uses a list of x and y .
Ameer Hamza
2018년 5월 2일
편집: Ameer Hamza
2018년 5월 2일
Try the following lines
BB = [1, 1, size(boxImage,2) size(boxImage,1)];
newImage = imcrop(sceneImage, BB);
figure;
imshow(newImage);
or as @Image Analyst suggested,
newImage = sceneImage(1:size(boxImage,1), 1:size(boxImage,2), :);
figure;
imshow(newImage);
Theodor Al Saify
2018년 5월 2일
the first solution cropped a piece of the whole detected object. in the second solution i received an Index exceeds matrix dimensions error.
Theodor Al Saify
2018년 5월 2일
1 , 1 parameter is not correct it should be the bottom left of the detected object
Ameer Hamza
2018년 5월 2일
Can you attach the live script you are using for this question? It will be easy to give a proper answer if the actual image is available.
Ameer Hamza
2018년 5월 2일
@Theodor Al Saify, it is very difficult to give a correct line of code because I don't know what the variable name represent. If you can attach the file, it will be easy to give the correct answer.
Theodor Al Saify
2018년 5월 2일
clc; warning('off','Images:initSize:adjustingMag'); boxImageRGB = imread('img5.JPG'); boxImage = rgb2gray(boxImageRGB); figure; imshow(boxImage); title('Image of a Box'); sceneImageRGB = imread('img2.JPG'); sceneImage = rgb2gray(sceneImageRGB); 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(selectStrongest(boxPoints, 100)); figure; imshow(sceneImage); title('300 Strongest Feature Points from Scene Image'); hold on; plot(selectStrongest(scenePoints, 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'); fprintf('new Box Polygon x ') disp(newBoxPolygon(:, 1)); fprintf('new Box Polygon y ') disp(newBoxPolygon(:, 2));
%crop the detected zone BB = [newBoxPolygon(1, 1), newBoxPolygon(1, 1), size(boxImage,1) size(boxImage,2) ]; newImage = imcrop(sceneImage, BB); figure; imshow(newImage);
% newImage = sceneImage(1:size(boxImage,1),1:size(boxImage,2),:); % figure; % imshow(newImage);
Theodor Al Saify
2018년 5월 2일
this is the code i am using , i changed the parameters of your code in order to find the correct coordinate .
Ameer Hamza
2018년 5월 2일
It appears that you made a mistake in this line. the second element should be newBoxPolygon(1, 2).
BB = [newBoxPolygon(1, 1), newBoxPolygon(1, 2), size(boxImage,1) size(boxImage,2) ];
try it now.
Ameer Hamza
2018년 5월 3일
Please also share img2.jpg and img5.jpg as I am not able to replicate the problem as described by you.
Ameer Hamza
2018년 5월 3일
There!!! Now I am able to see properly what is going on. Replace BB line with following
BB = [min(newBoxPolygon(:, 1)), min(newBoxPolygon(:, 2)), size(boxImage,1) size(boxImage,2) ];
추가 답변 (2개)
Theodor Al Saify
2018년 5월 2일
i am working on this image, i detected the desired object and drew a line around it. Now i want to crop the detected object to start working in it's area.

Theodor Al Saify
2018년 5월 2일
편집: Theodor Al Saify
2018년 5월 2일
when using ur code i get this result. the starting point of the rectangle is not correct

댓글 수: 2
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)


