Community RSS Feed
https://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions in tag Image Processing sorted by activeFourier Transforms and 'Hybrid Images' in the Wolfram Language
https://community.wolfram.com/groups/-/m/t/1592896
![A mandrill-pepper hybrid][1]
Recently, I was asked to assist somebody with graphing the Fourier transform of an image. The resulting images were neat, and the work reminded me of a really fun application of Fourier transforms: [Hybrid Images][2]
By taking the Fourier transforms of two images, and combining the high-frequency parts of one with the low-frequency parts of the other, you get an image that looks like one thing when your eyes are focused, and another thing when they are unfocused. The classic example is the Einstein – Marilyn Monroe image.
![Einstein - Marilyn Monroe][3]
Of course, the above example is in black and white, so a natural extension would be to include color. Also, I would like to explore how the image changes as I vary how much of each image is included.
Thankfully, both of these things are easy to do in the Wolfram Language.
As a warmup, let’s simply visualize the Fourier transform of an image by itself. I use one of the test images provided in ExampleData[].
`
mandrill=ExampleData[{"TestImage","Mandrill"}]
`
![Mandrill test image][4]
`
mandrill2 = ColorSeparate[mandrill];
`
With the `ColorSeparate` function, I split the image into its RGB channels. I will be taking the Fourier transform of each of these.
`
shift := Table[(-1)^(i + j) #[[i]][[j]], {i, 1, Length[#]}, {j, 1, Length[#[[1]]]}] &
mandrill3 = Fourier[shift@ImageData@#] & /@ mandrill2;
`
Before taking the transform, I apply a function `shift` to the image, so that the low frequencies of the image will appear at the center of the Fourier transformed image, rather than at the edges.
`
ColorCombine[Image /@ Abs[mandrill3]]
`
![Fourier Transform of Mandrill][5]
And there we have the Fourier transform of our mandrill.
To put it all together, we could write this as
`
ColorCombine[
Image /@ Abs /@
Fourier /@ shift /@ ImageData /@ ColorSeparate[mandrill]]
`
Now that we’ve got the warm-up out of the way, we want to take two different images, and mix them together. We’ll need two images that are the same size, so I’ll set it to manually resize the images to 512*512. All the example images are that size already, but you may need to resize if you want to use something else.
`
size = 512;
test1 = ImageResize[ExampleData[{"TestImage", "Mandrill"}], size];
test2 = ImageResize[ExampleData[{"TestImage", "Peppers"}], size];
ft1 = Fourier /@ shift /@ ImageData /@ ColorSeparate[test1];
ft2 = Fourier /@ shift /@ ImageData /@ ColorSeparate[test2];
`
Now we can make a temporary variable based on one image, and replace a square of size `2x` in the center of the Fourier-transformed image with the corresponding elements of the other image.
`
Manipulate[
Module[{temp = ft1},
temp[[1;;3,size/2-x;;size/2+x,size/2-x;;size/2+x]]=ft2[[1;;3,size/2-x;;size/2+x,size/2-x;;size/2+x]];
ColorCombine[Image/@Abs/@InverseFourier/@temp]],
{x,1,size/2-1,1}]
`
This generates a manipulate box where you can control how much of each image is included. For this example I find that `x=45` or so is the sweet spot for making the Mandrill 'hidden' when seen from afar, as included at the top of the post. We can also swap the two images, and have some hidden peppers in a picture of a Mandrill.
![A pepper-mandrill hybrid][6]
Hopefully, some of you find this as fun as I do. I attach the notebook I used to generate these hybrid images.
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Mathematica_8EZiogEXIi.png&userId=1541430
[2]: https://en.wikipedia.org/wiki/Hybrid_image
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Hybrid_image_decomposition.jpg&userId=1541430
[4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Mandrill.png&userId=1541430
[5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=FTMandrill.png&userId=1541430
[6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Mathematica_4m1iGQm2JR.png&userId=1541430Duncan Pettengill2019-01-16T18:22:25ZAdd a SoftmaxLayer to trainable network with vector input 14x14 pixel pics?
https://community.wolfram.com/groups/-/m/t/1592948
Dear all,
I have a working trainable network. The input is a vector of 14 x 14 pixel images, the output is a vector with three elements. Now I would like the output vector to be normalized. For this reason I added a SoftmaxLayer[], however NetTrain now complains "expected a vector of 1 to 3 indices."
Here's the working network:
...more layers...
layer10 = LinearLayer[{3}];
layer11 = ElementwiseLayer[ Tanh ];
Net = NetChain[{layer1, layer2, layer3, layer4, layer5, layer6, layer7, layer8, layer9, layer10, layer11}];
Here's the code that leads to the error from NetTrain:
...more layers...
layer10 = LinearLayer[{3}];
layer11 = ElementwiseLayer[ Tanh ];
layer12 = FlattenLayer[];
layer13 = SoftmaxLayer[];
Net = NetChain[{layer1, layer2, layer3, layer4, layer5, layer6,
layer7, layer8, layer9, layer10, layer11, layer12, layer13}];
TrainedNet = NetTrain[Net, <| "Input" -> Images, "Output" -> Labels|>, {MaxTrainingRounds -> 256, Method -> "ADAM", BatchSize -> 128, ValidationSet -> Scaled[0.2]}]
(NetTrain::notiintvec: Expected a vector of indices between 1 and 3.):
It seems to be required to add a FlattenLayer[], because the ElementwiseLayer returns a layer of tensors due to Tanh[]. As per examples, it should be working without the flattening. Can anyone point me to where I have gone wrong?Markus Lenzing2019-01-16T13:17:11ZRetrieve the Adain-Style (ImageRestyle) network?
https://community.wolfram.com/groups/-/m/t/1592304
I cannot retrieve the Adain-Style (ImageRestyle) network. The download aborts about halfway through.Collin Merenoff2019-01-15T01:27:39Z