6
$\begingroup$

I often download images with two borders (frame and mat). Here is an example downloaded from link:

enter image description here

img = Import["mydirectory/" <> "man ray 1924.jpeg"]

Not having much experience with Mathematica's image processing features I thought that cropping twice would remove the two borders:

ImageCrop @ ImageCrop @ img

enter image description here

But the second ImageCrop doesn't change anything - only the frame is removed.

Doing the cropping manually (which is cumbersome) gives

ImageTake[img, {60, 350}, {65, 290}]

enter image description here

Question

Is there a way to get the above result automatically?

$\endgroup$

2 Answers 2

4
$\begingroup$
img = Import["https://i.sstatic.net/qAlmj.jpg"];
ImagePad[img, -BorderDimensions[GradientFilter[img, 1], 0.1]]

enter image description here

$\endgroup$
5
$\begingroup$
  • Since there are some letters on the right down corner,the crop seems not so perfect.
img = Import["https://i.sstatic.net/qAlmj.jpg"];
dim = Information[ImageCrop@ColorNegate@Binarize@img][
  "ImageDimensions"]
ImageCrop[img, dim]

enter image description here

  • The method by @Domen in the comment.
img = Import["https://i.sstatic.net/qAlmj.jpg"];
{dim1, dim2} = 
 BorderDimensions[
  ColorNegate@Binarize@img]; ImageTake[img, {-1, 1}  dim2 // 
  Reverse, {-1, 1}  dim1 // Reverse]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ It does not work properly not due to the letters in the right-down corner, but because using only "ImageDimensions", you are cropping symmetrically from all borders. Instead, try something like {{x1, x2}, {y1, y2}} = BorderDimensions[ColorNegate@Binarize@img]; ImageTake[img, {y2, -y1}, {x2, -x1}] $\endgroup$
    – Domen
    Mar 25 at 11:18
  • $\begingroup$ @Domen Thanks, such method work fine. $\endgroup$
    – cvgmt
    Mar 25 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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