You can manipulate the image pyramid via its properties. In this case, the “Levels” property. For simplicity, let’s do this on one of the images in your a list.
horsePyramid = ImagePyramid[a[[1]], "Laplacian", 4, 2];
horsePyramid["Levels"] = MapAt[-# &, horsePyramid["Levels"], {1 ;; -2}];
InverseImagePyramid[horsePyramid]
Let me know if you want a version that you can map over a list of images or image pyramids–it’s slightly tricky, but do-able.
The basic problem is that when you use Set, you need a variable on the left hand side. In this expression,
animalPyramid[[1]]["Levels"]
the animalPyramid[[1]] bit evaluates to a literal ImagePyramid expression, and so you get the error.
The tricky bit is that these special wrapper “objects”, in this case ImagePyramid, don’t always give you easy ways to manipulate them naturally. What I think we’re going to have to do is destructure the ImagePyramid and then put it back together again.
I’m going to generalize a bit so you can adapt this to different manipulations you might want to perform:
PyramidAdjust[fn_, positions_, pyr_] :=
ImagePyramid[MapAt[fn, pyr[[1]], {"Levels", Splice[positions]}]]
You can use it like this:
PyramidAdjust[-# &, {1 ;; -2}, ImagePyramid[a[[1]], "Laplacian", 4, 2]]
So, pass a function that you want to apply to the levels, an expression indicating which exact levels you want to apply the function to, and an ImagePyramid “object”.
Let’s use this in Map.
pyramids = ImagePyramid[#, "Laplacian", 4, 2] & /@ a;
PyramidAdjust[Function[x, -x], {1 ;; -2}, #] & /@ pyramids
Notice I changed -#& to Function[x, -x] to remove ambiguity with the nested functions.
We could map InverseImagePyramid over this:
InverseImagePyramid /@ (PyramidAdjust[Function[x, -x], {1 ;; -2}, #] & /@ pyramids)
Notice the parentheses–we need them to force the desired precedence.
Eric, this is exactly what I was looking for! It is a very elegant solution to my problem. Since I am somewhat new to Mathematica this would have taken me a long long time to figure out. I really appreciate the effort you put into this, and I learned a lot! Thanks again,
Rich
No problem! I just want to point out that this situation was weird. I’m not even sure it’s really necesary to do what I did, but I’m just not familiar with ImagePyramid and so ended up “hacking” it. Don’t let this experience set expectations about how Mathematica typically works.
Mathematica is a fantastic program, and I won’t let this experience set expectations about how it works.
However, I should note that this experience continues to reinforce the positive impression that I have of the Wolfram Community. I have used it several times to learn more about Mathematica. So far all of the responses (including yours) have been excellent.