Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a series of mouse MRI images, here are two

enter image description here

enter image description here

How can I automatically remove the metal cage around the mouse to make it look like this:

enter image description here

The position of the cage is not always in exactly the same position. Making the image more horizontal would also be nice. Also each image should have the same dimensions.

image1 = Import["http://i.imgur.com/iGia7W6.jpg"]
share|improve this question

1 Answer 1

You could use ImageLines to locate the straight edges:

image1 = Import["http://i.stack.imgur.com/xni6T.jpg"];
lines = ImageLines[EdgeDetect@image1, MaxFeatures -> 4];
Show[image1, Graphics[{Thick, Orange, Line /@ lines}]]

enter image description here

Then ImageRotate to straighten the image, and then re-detect the lines:

image1 = ImageRotate[image1, Pi - Mean[ArcTan @@@ Subtract @@@ lines], Full];
lines = ImageLines[EdgeDetect@image1, MaxFeatures -> 4];
Show[image1, Graphics[{Thick, Orange, Line /@ lines}]]

enter image description here

Then isolate the two inner lines and trim the image:

lines = SortBy[lines, #[[1, 2]] &][[{2, 3}]];
ImageTrim[image1, Flatten[lines, 1]]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.