Adding alpha value to imager object

background

I am working on a function which superimposes two images on top of each other using R. Images are stored as .jpg files, with the paths to each image stored in a csv file so the function knows which images to superimpose.

Images are loaded in with the imager package (load.image()), and at this point I want to set an alpha (translucency) value, otherwise I can only see the top image after they are superimposed.

The two source images for each superimposition are two-tone thresholded black and white images, which I've used the following code to colourise and create cyan and magenta versions of the images: (slightly modified for im2)
im1 <- as.raster(
array(
c(
t(matrix(1, nrow = height, ncol = width)),
t(as.matrix(im1.m)),
t(matrix(1, nrow = height, ncol = width)),
t(matrix(alpha, nrow = height, ncol = width))
),
c(height, width, 4)
)
)

This code already contains an alpha value (alpha is a variable set at the beginning), but the images don't seem to have any translucency. Is there a reason the code isn't making the images translucent?

They are then converted to Magick objects and superimposed using the following:

Create the two layers of the image in Magick

im1.im2 <- c(im1, im2) # layer up - combo 1
superimposed_imv1 <<- image_mosaic(im1.im2) # superimpose the images

This is supposed to create a single image where both images are visible, but I can only see the front image.

Apologies if my format is a bit off, it's my first time posting on this forum.

Thanks for any help in advance!

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.