You should set the BitDepth as the last operation before you write your image because this will clamp your pixels to 12 bit. You should do it like this:
p.s. I am only writing this in VB because you got me the book :) Otherwise I would translate it to C#
Using image AsNew MagickImage(input) image.AddProfile(ColorProfile.SRGB) 'Are you sure you need this? image.Gamma(0.454544) image.ColorMatrix(matrix) ' This will create "out of range" pixels. image.Gamma(2.6) image.BitDepth(12) 'I added a new overload that accepts an integer. image.Write(output) EndUsing