I want to apply the Vegetation Change Tracker (vct) algorithm using Landsat time series. I have removed the water bodies out of the images, I have computed the FZ and IFZ values so that every image has the latter values written on it and lastly I have created a time series stack. What I am struggling to understand is how I can compare in a consecutive way the layers of the raster stack (e.g. raster2-raster1, raster3-raster2 etc.). VCT's flowchart is the following: a) if a pixel has an IFZ < 3 in the entire study period then classify it as 1, b) if a pixel had an IFZ < 3 but NOT for 2 consecutive years then classify it as 2, c) if a pixel had an IFZ < 3 for more than 2 consecutive years following by an IFZ > 3 for 2 consecutive years then classify it as 3, d) if it has an IFZ > 3 in the entire period classify it as 4. The goal is a raster which will have one of the 4 values.
Theoretically I know what I have to do but practically I do not know how to make the substraction among consecutive years. Please help me. I have insert an image of the flowchart of the vct algorithm. I am using R.