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.