Skip to contents

step_measure_baseline_tophat() creates a specification of a recipe step that applies top-hat morphological baseline correction.

Usage

step_measure_baseline_tophat(
  recipe,
  measures = NULL,
  half_window = 50L,
  role = NA,
  trained = FALSE,
  skip = FALSE,
  id = recipes::rand_id("measure_baseline_tophat")
)

Arguments

recipe

A recipe object.

measures

An optional character vector of measure column names.

half_window

Half-window size for the structuring element. Default is 50.

role

Not used.

trained

Logical indicating if the step has been trained.

skip

Logical. Should the step be skipped when baking?

id

Unique step identifier.

Value

An updated recipe with the new step added.

Details

The top-hat transform is a morphological operation that extracts bright features (peaks) from a dark background. It is computed as the difference between the original signal and its morphological opening.

This is effective for chromatography with sharp, well-defined peaks on a smooth baseline.

Examples

library(recipes)

rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
  update_role(id, new_role = "id") |>
  step_measure_input_long(transmittance, location = vars(channel)) |>
  step_measure_baseline_tophat(half_window = 30) |>
  prep()