現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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 .
Theodor Al Saify
2018 年 5 月 2 日
no still i can't find the right starting point to start the rectangle
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)


