I have a very specific script I am trying to make which computes image flatfields. Basically, I am computing a Master Dark Frame (MD) by averaging a set of Dark Photos.
I have a set of light photos as well. I want to take the averaged dark photo and subtract that average from each light photo within a directory. After this, a Master Flat (MF) is made by averaging all the light photos which had been subject to dark frame subtractions.
Here is my script so far:
library(rgdal) library(raster) ##Takes all dark frame images from within working directory and stacks them into a single object darkrastdat<- list.files() darkstack<- stack(darkrastdat) ##computes the mean of all dark layers/pixels within the object, omits no- data values masterdark <- mean(darkstack, na.rm=TRUE) ##loads each light frame into an object lightrastdat<- list.files() ##subtracts master dark from each light frame ##stacks and averages light frames ##writes master flat as 16-bit into original working directory writeRaster(mrast, filename= "MF.tif", datatype='INT2U', overwrite=TRUE)
I am able to get an master dark frame (MD) from within a directory of photos. I am having trouble coming up with a way to subtract that MD from each light frame individually.
Can anyone give me some advice?