I want to rotate this image by -50 degrees, and then fill up the black space around the rotated image
with a bluish color. I can't find any documentation/answers that suggest how to do it. (Sorry about the poor question formatting).
2 Answers
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"}}]
-
-
$\begingroup$ Could be tidied up a lot more but do not have time at present $\endgroup$– ubpdqnJun 22, 2015 at 6:04
-
$\begingroup$ The
"TextureSynthesis"
setting looks to be the best for me. $\endgroup$ Jun 22, 2015 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$– ubpdqnJun 22, 2015 at 10:11
-
As already commented you can use the Background
option for ImageRotate
.
You might use DominantColors
to select a background color.
img = Import["https://i.stack.imgur.com/Qr60D.png"];
ImageRotate[img, -50 °,
Background -> DominantColors[img, 1]]
-
$\begingroup$ thank you for introducing me to
DominantColors
+1 for that. :) $\endgroup$– ubpdqnJun 22, 2015 at 5:24
ImageRotate[]
takes aBackground
option. Set it to something likeImageRotate[img, Background -> Blue]
. $\endgroup$Padding -> "Fixed"
orPadding -> "Reversed"
to repeat the pixel values of the image itself. $\endgroup$