3
$\begingroup$

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"]
$\endgroup$
7
$\begingroup$

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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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