grid_to_index-methods: Generic function to convert N-dimensional grid coordinate to...

grid_to_indexR Documentation

Generic function to convert N-dimensional grid coordinate to 1D indices

Description

Converts 2D grid coordinates to linear indices for a NeuroSlice object.

Usage

grid_to_index(x, coords)

## S4 method for signature 'NeuroSlice,matrix'
grid_to_index(x, coords)

## S4 method for signature 'NeuroSlice,numeric'
grid_to_index(x, coords)

## S4 method for signature 'NeuroSpace,matrix'
grid_to_index(x, coords)

## S4 method for signature 'NeuroSpace,numeric'
grid_to_index(x, coords)

## S4 method for signature 'NeuroVol,matrix'
grid_to_index(x, coords)

## S4 method for signature 'NeuroVol,numeric'
grid_to_index(x, coords)

Arguments

x

A NeuroSlice object

coords

Either a numeric vector of length 2 or a matrix with 2 columns, representing (x,y) coordinates in the slice grid

Details

Convert Grid Coordinates to Linear Indices

Value

a vector of indices

Integer vector of linear indices corresponding to the input coordinates

See Also

index_to_grid for the inverse operation

Examples

slice_space <- NeuroSpace(c(10, 10))
slice_data <- matrix(1:100, 10, 10)
slice <- NeuroSlice(slice_data, slice_space)

# Convert single coordinate
idx <- grid_to_index(slice, c(5, 5))

# Convert multiple coordinates
coords <- matrix(c(1,1, 2,2, 3,3), ncol=2, byrow=TRUE)
indices <- grid_to_index(slice, coords)


bbuchsbaum/neuroim2 documentation built on Jan. 2, 2025, 3:38 p.m.