# Linescan data

`detrendr` expects the time dimension to be the fourth dimension of the image (`y`, `x`, `channel`, `time`). Some people’s data is linescan, meaning there is only one spatial dimension (`x`) and time is placed along the `y` axis of the image. We have an example in this package. It’s 1,000 time points of a line of 64 pixels; it has 2 channels.

    linescan_img <- ijtiff::read_tif(system.file("extdata", "linescan.tif",
                                                 package = "detrendr"))
    #> Reading linescan.tif: an 8-bit, 1000x64 pixel image of
    #> unsigned integer type. Reading 2 channels and 1 frame . . .
    #> Done.
    dim(linescan_img)
    #> [1] 1000   64    2    1

As you can see, the image has 1,000 rows and 64 columns in its two channels, so time is indeed along the `y` axis. This won’t work with detrendr, so before detrending it, we need to put time on the fourth dimension. Fortunately, `ijtiff` provides a function for this.

    converted_img <- ijtiff::linescan_to_stack(linescan_img)
    dim(converted_img)
    #> [1]    1   64    2 1000

Now as you can see, time is on the fourth dimension, so we can proceed as normal.

    library(detrendr)
    detrended_converted_img <- img_detrend_rh(converted_img)
    dim(detrended_converted_img)
    #> [1]    1   64    2 1000

This image is still in stack format. You could now convert it back to linescan format if you like.

    linescan_detrended_img <- ijtiff::stack_to_linescan(detrended_converted_img)
    dim(linescan_detrended_img)
    #> [1] 1000   64    2    1

You can then do as you please with these results, such as save them with `ijtiff::write_tif()`.