0
$\begingroup$

I am attempting to apply nonlinear transformation to the bottom half of my image. I use the Masking option for ImageTransformation and use an array where the the only positive values are where I want the transformation applied. When the code is executed the transformation is applied to the bottom half of the image;however, the top half of my image is displayed as white. How do I make it such that the top half of the image remains the same? My code is below(where image is image used in ImageTransformation:

greyPineApple = ColorConvert[Reflected, "Grayscale"];
greyValues = ImageData[greyPineApple];
greyValues = greyValues[[All, All, 1]];
zeroFunction[x_] := 0*x;
greyValues[[All, All]] = 0;
greyValues[[367 ;; 700, 65 ;; 220]] = 1;
ImageTransformation[image, # + .02 Sin[20 # + 25] &, Masking -> greyValues]
$\endgroup$
1
$\begingroup$

Unfortunately Masking doesn't control where the the transform is applied, it just masks result image. However, you can control where the mask is applied within the transformation function.

In the below #[[2]] is the y-coordinate which (since PlotRange and DataRange are defaulted to Automatic) has values between 0 and h/w = 1/Divide @@ ImageDimensions[image]. 427/790 is how far up from the bottom of the image to apply the transform.

ImageTransformation[image,
 If[#[[2]] < 427/790/(Divide @@ ImageDimensions[image])
   , # + .02 Sin[20 # + 25]
   , #] &
 , Padding -> "Fixed"
 ]

enter image description here

$\endgroup$
0
$\begingroup$

Another way maybe help:

pic = ImagePartition[ImageCrop[image], Scaled[{1, 1/2}]];
ImagePad[ImageAssemble[MapAt[ImageTransformation[#, # + .02 Sin[20 # + 25] &,
Padding -> "Reflected"] &, pic, {2, 1}]], 10, White]
$\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.