12
$\begingroup$

I want to rotate this image enter image description here by -50 degrees, and then fill up the black space around the rotated image enter image description here with a bluish color. I can't find any documentation/answers that suggest how to do it. (Sorry about the poor question formatting).

$\endgroup$
2
  • 1
    $\begingroup$ ImageRotate[] takes a Background option. Set it to something like ImageRotate[img, Background -> Blue]. $\endgroup$ – J. M.'s torpor Jun 22 '15 at 4:02
  • 1
    $\begingroup$ You could also try Padding -> "Fixed" or Padding -> "Reversed" to repeat the pixel values of the image itself. $\endgroup$ – user484 Jun 22 '15 at 4:24
21
$\begingroup$

Perhaps this will motivate others or your own much better answer. In the following imr is the rotated image and piece is a piece of texture cropped from the image. It is then placed in an image of same dimension as imr and the in-painted then used to in-paint.

id = ImageDimensions[imr];
mask = Erosion[Binarize[MorphologicalComponents[imr] // Colorize], 5];
ol = Rasterize[Overlay[{Image[Graphics[{}, ImageSize -> id]], piece}
    ]];
ip = Inpaint[ol, Binarize[ol]];
Inpaint[ImageAdd[ImageMultiply[imr, mask], ImageSubtract[ip, mask]], 
 ColorNegate@mask, Method -> "FastMarching"]

Options:

Manipulate[
 Inpaint[ImageAdd[ImageMultiply[imr, mask], ImageSubtract[ip, mask]], 
  ColorNegate@mask, Method -> method], {method,
  {"TotalVariation", "FastMarching", "NavierStokes", 
   "TextureSynthesis"}}]

enter image description here

$\endgroup$
6
  • $\begingroup$ Very nice! +1 :-) $\endgroup$ – Mr.Wizard Jun 22 '15 at 6:02
  • $\begingroup$ Could be tidied up a lot more but do not have time at present $\endgroup$ – ubpdqn Jun 22 '15 at 6:04
  • $\begingroup$ The "TextureSynthesis" setting looks to be the best for me. $\endgroup$ – J. M.'s torpor Jun 22 '15 at 10:09
  • $\begingroup$ @Guesswhoitis. I did this in a rush...could Abe done better. I too like texture synthesis and could crop out extraneous if desired...:) $\endgroup$ – ubpdqn Jun 22 '15 at 10:11
  • $\begingroup$ This is a beautiful answer. $\endgroup$ – George Wolfe Jun 22 '15 at 11:19
14
$\begingroup$

As already commented you can use the Background option for ImageRotate.
You might use DominantColors to select a background color.

img = Import["http://i.stack.imgur.com/Qr60D.png"];

ImageRotate[img, -50 °,
 Background -> DominantColors[img, 1]]

enter image description here

$\endgroup$
1
  • $\begingroup$ thank you for introducing me to DominantColors +1 for that. :) $\endgroup$ – ubpdqn Jun 22 '15 at 5:24

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.