Title: | Density Profiles of Wood from CT Scan Images |
---|---|
Description: | Computerized tomography (CT) can be used to assess certain wood properties when wood disks or logs are scanned. Wood density profiles (i.e. variations of wood density from pith to bark) can yield important information used for studies in forest resource assessment, wood quality and dendrochronology studies. The first step consists in transforming grey values from the scan images to density values. The packages then proposes a unique method to automatically locate the pith by combining an adapted Hough Transform method and a one-dimensional edge detector. Tree ring profiles (average ring density, earlywood and latewood density, ring width and percent latewood for each ring) are then obtained. |
Authors: | Dipak Mahatara [aut], Robert Schneider [cre, aut] |
Maintainer: | Robert Schneider <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-11-10 03:14:32 UTC |
Source: | https://github.com/cran/CTRing |
Add ring to pith to bark profile from CT scan image
addRingFromImage(n = 1, densProfile, im)
addRingFromImage(n = 1, densProfile, im)
n |
Number of rings to add |
densProfile |
Density profile |
im |
Density matrix |
Corrected density profile with new ring(s) added and blue bar in plot of added ring
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) image_info <- getImageInfo(hdr = hdr_df) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) newPath2 <- addRingFromImage(n = 1, densPath, im_dens)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) image_info <- getImageInfo(hdr = hdr_df) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) newPath2 <- addRingFromImage(n = 1, densPath, im_dens)
Add ring to pith to bark profile from profile plot
addRingFromProfile(n = 1, densProfile)
addRingFromProfile(n = 1, densProfile)
n |
Number of rings to add |
densProfile |
Density profile |
Corrected density profile with new ring(s) added and blue bar in plot of added ring
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(path) newPath <- addRingFromProfile(n = 1, path)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(path) newPath <- addRingFromProfile(n = 1, path)
Add years to series
addYears(lastYear, densProfile)
addYears(lastYear, densProfile)
lastYear |
Last year of series |
densProfile |
Density profile |
Density profile with years
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) path <- addYears(2021, path)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) path <- addYears(2021, path)
Calculate average wood, earlywood and latewood density for every ring
calcAvgDens(densProfile)
calcAvgDens(densProfile)
densProfile |
Density profile |
List with several vectors
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) pathEwLw <- getEwLw(path) plotProfile(pathEwLw) path_avgDens <- calcAvgDens(pathEwLw) names(path_avgDens)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) pathEwLw <- getEwLw(path) plotProfile(pathEwLw) path_avgDens <- calcAvgDens(pathEwLw) names(path_avgDens)
Verify position of ring transitions of a density profile
checkProfile(profile_with_borders, totRings)
checkProfile(profile_with_borders, totRings)
profile_with_borders |
xRing profile with transitions between rings located |
totRings |
Total number of rings of the disk |
xRing profile with corrected ring location
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) image_info <- getImageInfo(hdr = hdr_df) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) newPath <- checkProfile(densPath, 26)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) image_info <- getImageInfo(hdr = hdr_df) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) newPath <- checkProfile(densPath, 26)
Add ring to pith to bark profile from CT scan image
deleteRingFromImage(n = 1, densProfile, im)
deleteRingFromImage(n = 1, densProfile, im)
n |
Number of rings to remove |
densProfile |
Density profile |
im |
Density matrix |
Corrected density profile with ring(s) removed and red bar in plot of deleted ring
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) newPath2 <- addRingFromImage(n = 1, densPath, im_dens) oldPath2 <- deleteRingFromImage(n = 1, densPath, im_dens)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) newPath2 <- addRingFromImage(n = 1, densPath, im_dens) oldPath2 <- deleteRingFromImage(n = 1, densPath, im_dens)
Delete ring from a pith to bark profile
deleteRingFromProfile(n = 1, densProfile)
deleteRingFromProfile(n = 1, densProfile)
n |
Number of rings to remove |
densProfile |
Density profile |
Corrected density profile with ring(s) removed and red bar in plot of deleted ring
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(densPath) newPath <- addRingFromProfile(n = 1, densPath) oldPath <- deleteRingFromProfile(n = 1, newPath)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image densPath <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(densPath) newPath <- addRingFromProfile(n = 1, densPath) oldPath <- deleteRingFromProfile(n = 1, newPath)
Convert to dataframe
densityDataFrame(densProfile, sampleID = "NoID", addTransitionType = FALSE)
densityDataFrame(densProfile, sampleID = "NoID", addTransitionType = FALSE)
densProfile |
Density profile |
sampleID |
Sample ID |
addTransitionType |
add transition type to dataframe |
Dataframe with cambial age, density, years, transition type
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) pathEwLw <- getEwLw(path) plotProfile(pathEwLw) path_avgDens <- calcAvgDens(pathEwLw) densityDf <- densityDataFrame(pathEwLw)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) pathEwLw <- getEwLw(path) plotProfile(pathEwLw) path_avgDens <- calcAvgDens(pathEwLw) densityDf <- densityDataFrame(pathEwLw)
Automatically detect pith in a CT scan image
detect_pith( im, toPlot = TRUE, n_segments = 25, flag = TRUE, x_0 = 0.5, y_0 = 0.5, n_run_max = 15, threshold = 0.1, pixel = TRUE )
detect_pith( im, toPlot = TRUE, n_segments = 25, flag = TRUE, x_0 = 0.5, y_0 = 0.5, n_run_max = 15, threshold = 0.1, pixel = TRUE )
im |
Matrix of the CT scan image |
toPlot |
Boolean to plot the location of the pith on the image |
n_segments |
Number of segements used to locate pith |
flag |
FALSE if pith location is known |
x_0 |
Estimate of pith location in x |
y_0 |
Estimate of pith location in y |
n_run_max |
Maximum number of iterations |
threshold |
Thershold value for identifying ring transition points |
pixel |
If TRUE, returns x,y coordinates in pixel numbers, else FALSE returns x,y coordinates in relative values of x and y |
x,y pith coordinates
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE)
Get profile between two points of the CTScan image matrix
extractProfile( im, imHeader, beginPath, endPath, r = 10, k = 2, threshold = 0.01 )
extractProfile( im, imHeader, beginPath, endPath, r = 10, k = 2, threshold = 0.01 )
im |
Density matrix |
imHeader |
image header |
beginPath |
X,Y coordinates of the start point of the path |
endPath |
X,Y coordinates of the start point of the path |
r |
Profile width |
k |
Rolling window width, integer |
threshold |
Threshold value between maximum and minimum density to establish change of ring |
Density profile
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002)
Establish the transition point from earlywood to latewood for a series of rings
getEwLw(densProfile)
getEwLw(densProfile)
densProfile |
Density profile |
xRingList with EW to LW transition points with transition type added (1: low number of points in ring; 2: inflexion point estimated by polynomial; 3: min or max are out of range; 4: inflexion point close to min or max; 5: convex-concave)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) pathEwLw <- getEwLw(path) densityDf <- densityDataFrame(path)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) pathEwLw <- getEwLw(path) densityDf <- densityDataFrame(path)
Extract from header of CT scan image grayscale number of bits and pixel size
getImageInfo(hdr)
getImageInfo(hdr)
hdr |
Header dataframe |
List with grayscale values, and pixel size
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] getImageInfo(hdr = hdr_df)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] getImageInfo(hdr = hdr_df)
Convert from 8bit gray scale to density
grayToDensity(im, a = -0.1321, b = 0.01834)
grayToDensity(im, a = -0.1321, b = 0.01834)
im |
Matrix of CT scan image in 8bit gray scale |
a |
Intercept of the calibration curve |
b |
Slope of the calibration curve |
Matrix of density values
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) range(im_8bit) im_dens <- grayToDensity(im_8bit) range(im_dens)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) range(im_8bit) im_dens <- grayToDensity(im_8bit) range(im_dens)
Convert dicom image to matrix
imageToMatrix(img)
imageToMatrix(img)
img |
Dicom image |
Matrix of image
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) dim(im) image(im)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) dim(im) image(im)
Get coordinates of the end of the path on a CT scan image
locatePathEnd(im, pithCoord)
locatePathEnd(im, pithCoord)
im |
CT scan image |
pithCoord |
X,Y coordinates of the pith |
Coordinates of the end of the path
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image
convert pith coordinates from pixels to length units
pithCoordinates(pith_coord, pixel_size_x, pixel_size_y)
pithCoordinates(pith_coord, pixel_size_x, pixel_size_y)
pith_coord |
Pith coordinates in pixels |
pixel_size_x |
Pixel size in x |
pixel_size_y |
Pixel size in y |
Pixel coordinates in length units
Plot scan image, profile path and ring limits
plotImageProfile(densProfile, im)
plotImageProfile(densProfile, im)
densProfile |
Density profile |
im |
Density matrix |
Plot
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(path) plotImageProfile(path, im_dens)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(path) plotImageProfile(path, im_dens)
Plot density profile
plotProfile(densProfile)
plotProfile(densProfile)
densProfile |
Density profile |
Figure
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(path)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) plotProfile(path)
Change from relative to fixed pixel coordinate system
relToPixel(pith_coord, im)
relToPixel(pith_coord, im)
pith_coord |
Pith coordinates in relative space (x, y) |
im |
Density matrix |
Pixel coordinates in number of pixels (x, y)
Remove the last year of a profile
removeLastYear(densProfile)
removeLastYear(densProfile)
densProfile |
Density profile |
Density profile with the last year removed
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) path_last_year_2021 <- addYears(2021, path) path_last_year_2020 <- removeLastYear(path_last_year_2021)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) endPath <- c(472, 284) # manual # not run - endPath <- locatePathEnd(im_dens, pith_coord) # using the image path <- extractProfile(im_dens, image_info, pith_coord, endPath, k = 2, r = 5, threshold = 0.002) path_last_year_2021 <- addYears(2021, path) path_last_year_2020 <- removeLastYear(path_last_year_2021)
Check if pith location is correct
verifyPith(im, pith_coord)
verifyPith(im, pith_coord)
im |
Density matrix of image |
pith_coord |
Pith coordinates |
Corrected pith coordinates
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) pith_coord_checked <- verifyPith(im_dens, pith_coord)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) im_8bit <- xBitTo8Bit(im, image_info$grayScale) im_dens <- grayToDensity(im_8bit) pith_coord <- detect_pith(im_dens, n_segments = 12, pixel = TRUE, toPlot = FALSE) pith_coord_checked <- verifyPith(im_dens, pith_coord)
Convert gray scale from measured bits to 8bit
xBitTo8Bit(im, bits)
xBitTo8Bit(im, bits)
im |
Matrix of values in x bits |
bits |
Number of bits of the original gray scale |
Matrix of gray scale values in 8bits
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) range(im) im_8bit <- xBitTo8Bit(im, image_info$grayScale) range(im_8bit)
library(oro.dicom) file_path <- system.file("extdata", "disk.dcm", package = "CTRing") dcm <- readDICOM(file_path) hdr_df <- dcm$hdr[[1]] image_info <- getImageInfo(hdr = hdr_df) im <- imageToMatrix(dcm$img) range(im) im_8bit <- xBitTo8Bit(im, image_info$grayScale) range(im_8bit)