How to segment a white rectangle inside an other rectangle(black)?

1 view (last 30 days)
My scenario is.. I have an image that is of dimension 400X400 which is of black color. I have an other white rectangle of size 260X300 inside that black rectangle (whose sides are not parallel with the big one) white rectangle is rotated by some angle. how do i segment the rotated rectangle and fit at the center of the matrix(all values equals to one i.e a white a white image).

Accepted Answer

Image Analyst
Image Analyst on 31 Jan 2015
It's trivial:
binaryImage = grayImage > 128;
imshow(binaryImage);
I don't know what "fit at the center" means. If you want to translate the image so that its centroid is in the middle of the image you can use regionprops() and circshift().
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Centroid');
deltaX = .....
deltaY = ......
outputImage = circshift(...... etc.
It's pretty easy so I'll let your figure it out - you'll learn more that way. See attached demo if you need help.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!