I have an image and want to make a rectangle around black part which is in the middle of image.

回答 (2 件)

Dishant Arora
Dishant Arora 2014 年 6 月 23 日
Go for connected component labelling and check out for bounding boxes parameter, plot it. For more information check out this demo by image analyst Image Segmentation Tutorial ("BlobsDemo")

1 件のコメント

abhishek
abhishek 2014 年 6 月 23 日
sir i tried that code but its not working as i want. I tried bounding box, regionprops etc. but failed. so plz can you simply make some code for this situation.

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

Image Analyst
Image Analyst 2014 年 6 月 23 日
What are you starting with? A gray scale image, or that binary image? If you have that binary image, you might want to call imclose() to connect some regions together, then call bwareaopen() to get rid of small noise regions, Then call regionprops and get the centroids and bounding boxes. Find the centroid closest to the center of the image and extract only that one with ismember.

9 件のコメント

abhishek
abhishek 2014 年 6 月 23 日
i started with color image then converted it into gray.
Image Analyst
Image Analyst 2014 年 6 月 23 日
Did you try what I said? Why does your binary image in your second image look much, much different than from your original question?
abhishek
abhishek 2014 年 6 月 23 日
this is my file which have all experiments to achieve my goal but still nothing happen. I applied functions as you said sir. I just simply want a code which detect any obstacle in image and gave a path. or at least detect obstacle.
Image Analyst
Image Analyst 2014 年 6 月 23 日
I don't have robust code for that, which will recognize any objects that doesn't "belong" in the image along the "path" that you want to travel. It would be very difficult, especially if the floor has different patterns and colorations.
abhishek
abhishek 2014 年 6 月 24 日
ok no prob. sir. now i want to get the center point of current image and fetch the pixel distance and angle from center to colored obstacle in image
.
[rows, columns] = size(binaryImage);
midx = columns/2; % Compute center of image.
midy = rows/2;
% Get centroids
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Centroid');
abhishek
abhishek 2014 年 6 月 25 日
Now sir i have to find out the distance between centroid point and the detected obstacle. Just like in this image there is a blue circle which is Centroid point and want to fetch pixel distance between centeroid point to both obstacle. And in last angle from center.
Image Analyst
Image Analyst 2014 年 6 月 25 日
Can't you just use the Pythagorean theorem? Or hypot()?
abhishek
abhishek 2014 年 6 月 26 日
編集済み: abhishek 2014 年 6 月 26 日
hello sir. how can i find out the black pixel locations in an image and distance between center to that point.

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

質問済み:

2014 年 6 月 23 日

編集済み:

2014 年 6 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by