23
Package ‘CRImage’ March 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date 2012-10-01 Author Henrik Failmezger <[email protected]>, Yinyin Yuan <[email protected]>, Os- car Rueda <[email protected]>, Flo- rian Markowetz <[email protected]> Maintainer Henrik Failmezger <[email protected]>, Yinyin Yuan <[email protected]> Description CRImage provides functionality to process and analyze images, in particular to clas- sify cells in biological images. Furthermore, in the context of tumor images, it provides function- ality to calculate tumour cellularity. License Artistic-2.0 LazyLoad yes Imports MASS, e1071, foreach, sgeostat Depends EBImage, DNAcopy, aCGH Collate plotCorrectedCN.R correctCopyNumber.R writeDensityImage.R convertRGBToHSV.R convertHSVToRGB.R imageCompression.R createBinaryImage.R colorCorrection.R searchStructures.R segmentStructures.R classifyStructures.R numberOfNeighbors.R segmentCytoplasma.R segmentImage.R createClassifier.R kernelSmoother.R paintCells.R classifyCells.R determineCellularity.R calculateCellularity.R findSlices.R parseFinalScan.R classificationAperio.R processAperio.R Phansalkar_threshold.R SauvolaThreshold.R calculateMeanStdTarget.R convertLABToRGB.R convertRGBToLAB.R localORThreshold.R oregonThreshold.R localThreshold.R calculateOtsu.R classifyPen.R getImageDistance.R hist3d.R labelCells.R plotImage.R biocViews CellBiology, Classification git_url https://git.bioconductor.org/packages/CRImage git_branch RELEASE_3_10 git_last_commit a318c37 1

Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

Package ‘CRImage’March 25, 2020

Type Package

Title CRImage a package to classify cells and calculate tumourcellularity

Version 1.34.0

Date 2012-10-01

AuthorHenrik Failmezger <[email protected]>, Yinyin Yuan <[email protected]>, Os-car Rueda <[email protected]>, Flo-rian Markowetz <[email protected]>

Maintainer Henrik Failmezger <[email protected]>, Yinyin Yuan

<[email protected]>

Description CRImage provides functionality to process and analyze images, in particular to clas-sify cells in biological images. Furthermore, in the context of tumor images, it provides function-ality to calculate tumour cellularity.

License Artistic-2.0

LazyLoad yes

Imports MASS, e1071, foreach, sgeostat

Depends EBImage, DNAcopy, aCGH

Collate plotCorrectedCN.R correctCopyNumber.R writeDensityImage.RconvertRGBToHSV.R convertHSVToRGB.R imageCompression.RcreateBinaryImage.R colorCorrection.R searchStructures.RsegmentStructures.R classifyStructures.R numberOfNeighbors.RsegmentCytoplasma.R segmentImage.R createClassifier.RkernelSmoother.R paintCells.R classifyCells.RdetermineCellularity.R calculateCellularity.R findSlices.RparseFinalScan.R classificationAperio.R processAperio.RPhansalkar_threshold.R SauvolaThreshold.RcalculateMeanStdTarget.R convertLABToRGB.R convertRGBToLAB.RlocalORThreshold.R oregonThreshold.R localThreshold.RcalculateOtsu.R classifyPen.R getImageDistance.R hist3d.RlabelCells.R plotImage.R

biocViews CellBiology, Classification

git_url https://git.bioconductor.org/packages/CRImage

git_branch RELEASE_3_10

git_last_commit a318c37

1

Page 2: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

2 CRImage-package

git_last_commit_date 2019-10-29

Date/Publication 2020-03-24

R topics documented:CRImage-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2calculateCellularity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3calculateMeanStdTarget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5calculateOtsu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6classifyCells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7colorCorrection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8convertHSVToRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9convertLABToRGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10convertRGBToHSV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11convertRGBToLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11correctCopyNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12createBinaryImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13createClassifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15labelCells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16plotCorrectedCN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17processAperio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18SauvolaThreshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20segmentImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Index 23

CRImage-package CRImage is a package to analyze images and classify cells.

Description

CRImage allows classification of cells in biological images. It offers methods to segment cellsor cell nuclei in biological images for example HE stained images. It offers methods to create aclassifier and to classify cells in these images. Furthermore it allows the calculation of tumourcellularity for large microscope images.

CRImage makes use of the image processing package EBImage, which uses the ’ImageMagick’library for image I/O operations and the ’GTK’ library to display images.

Details

Package: CRImageType: PackageVersion: 1.0Date: 2010-04-27License: LGPL Version 2 or laterLazyLoad: yes

Page 3: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

calculateCellularity 3

Package content

Image processing methods:

• calculateThreshold

• segmentImage

Classification:

• createTrainingSet

• createClassifier

• classifyCells

Tumour cellularity

• calculateCellularity

• processAperio

Author(s)

Henrik Failmezger, <[email protected]>

Yinyin Yuan, <[email protected]>

Oscar Rueda, <[email protected]>

Florian Markowetz, <[email protected]>

CRI Cambridge

Li Ka Shing Centre

Robinson Way

Cambridge, CB2 0RE, UK

Ludwigs-Maximilians University of Munich

Examples

example(segmentImage)example(createClassifier)example(classifyImage)

calculateCellularity Calculation of tumour cellularity

Description

The function calculates the tumour cellularity of an image by counting tumour and non tumourcells.

Usage

calculateCellularity(filename="",image=NA,classifier=NULL,cancerIdentifier=NA,KS=FALSE,maxShape=NA,minShape=NA,failureRegion=NA,colors=c(),threshold="otsu",classesToExclude=c(),numWindows=2,classifyStructures=FALSE,pixelClassifier=NA,ksToExclude=c(),densityToExclude=c(),numDensityWindows=4)

Page 4: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

4 calculateCellularity

Arguments

filename A path to an image file.

image If filename is undefined, an Image object

classifier A SVM object, created with createClassifier or directly with the package e1071cancerIdentifier

A string which describes, how the cancer class is named.

KS Apply kernel smoother?

maxShape Maximum size of cell nuclei

minShape Minimum size of cell nuclei

failureRegion minimum size of failure regions

colors Colors to paint the classes

threshold Which threshold should be uses, "otsu" or "phansalkar"classesToExclude

Should a class be excluded from cellularity calculation?

numWindows Number of windows for the threshold.classifyStructures

Use hierarchical classification. If yes a pixel classifier has to be defined.pixelClassifier

A SVM to classify pixel based on their color values. Needed if hierarchicalclassification should be applied.

ksToExclude These classes are excluded from kernel smoothing.densityToExclude

This class is excluded from cellularity calculation.numDensityWindows

Number of windows for the density plot.

Details

The method calculates tumour cellularity of an image. The cells of the image are classified and thecellularity is: numTumourCells/numPixel. Furthermore the number of cells of the different classesare counted. A heatmap of cellularity is created. The image is divided in 16 subwindows andcellularity is calculated for every subwindow. Green in the heatmaps indicates strong cellularity,white low cellularity.

Value

A list containing

cellularity values

a vector, the n first values indicate the n numbers of cells in the n classes, then + 1th value indicates the tumour cellularity, The n + 2th value is the ratio oftumour cells by all cells

cancerHeatmap Heatmap of cancer density

Author(s)

Henrik Failmezger, [email protected]

Page 5: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

calculateMeanStdTarget 5

Examples

t = system.file("extdata", "trainingData.txt", package="CRImage")#read training datatrainingData=read.table(t,header=TRUE)#create classifierclassifier=createClassifier(trainingData)[[1]]#calculation of cellularityf = system.file("extdata", "exImg.jpg", package="CRImage")exImg=readImage(f)cellularity=calculateCellularity(classifier=classifier,filename=f,KS=TRUE,maxShape=800,minShape=40,failureRegion=2000,classifyStructures=FALSE,cancerIdentifier="c",numDensityWindows=2,colors=c("green","red"))

calculateMeanStdTarget

Calculates Mean and Standard deviation of an image

Description

Mean and SD calculation

Usage

calculateMeanStdTarget(imgT)

Arguments

imgT the Image to calculate.

Details

Mean and SD

Value

Vector with mean and standard deviation.

Author(s)

Henrik Failmezger, [email protected]

Examples

#read the target imagef1= system.file("extdata", "exImg2.jpg", package="CRImage")targetImage=readImage(f1)#read the image whose color values should be adaptedf2= system.file("extdata", "exImg3.jpg", package="CRImage")imgToConvert=readImage(f2)#calculate mean and standard deviation of target color channelsmst=calculateMeanStdTarget(targetImage)# create a white pixel mask

Page 6: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

6 calculateOtsu

whitePixelMask=imgToConvert[,,1]>0.85 & imgToConvert[,,2]>0.85 & imgToConvert[,,3]>0.85#adapt color channels of imageimgCorrected=colorCorrection(imgToConvert,mst,whitePixelMask)

calculateOtsu Does Otsu thresholding

Description

The function applies Otsu thresholding on the image.

Usage

calculateOtsu(allGreyValues)

Arguments

allGreyValues Vector of grey values.

Details

The function calculates a value which separates the grey value histogram the best in foreground andbackground.

Value

the threshold

Author(s)

Henrik Failmezger, [email protected]

References

Nobuyuki Otsu: A threshold selection method from grey level histograms. In: IEEE Transactionson Systems, Man, and Cybernetics. New York 9.1979, S.62-66. ISSN 1083-4419

See Also

calculateThreshold localOtsuThreshold

Examples

f1= system.file("extdata", "exImg2.jpg", package="CRImage")print(f1)img=readImage(f1)print(img)#convert to grayscaleimgG=EBImage::channel(img,'grey')#threshold valuet=calculateOtsu(as.vector(imgG))

Page 7: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

classifyCells 7

classifyCells A function to classify cells

Description

The function classifies cells and paints the different class types in the image.

Usage

classifyCells(classifier,filename="",image=NA,segmentedImage=NA,featuresObjects=NA,paint=TRUE,KS=FALSE,cancerIdentifier=NA, maxShape=NA,minShape=NA,failureRegion=NA,colors=c(),classesToExclude=c(),threshold="otsu",numWindows=2,structures=NA,classifyStructures=FALSE,pixelClassifier=NA,ksToExclude=c())

Arguments

classifier A Support Vector Machine created by createClassifier or directly by the packagee1071

filename A path to an image file.image An ’Image’ object or an array.segmentedImage An ’Image’ object or an array.The corresponding segmented image (created by

segmentImage)featuresObjects

Cell feature file of the segmentedImage (created by segmentImage)paint If true, the classified cells are painted with different colors in the imageKS Use Kernel Smoohter in classification?cancerIdentifier

A string which describes, how the cancer class is named.maxShape Maximum size of cell nucleiminShape Minimum size of cell nucleifailureRegion minimum size of failure regionscolors Colors to paint the classesclassesToExclude

Which class should be excluded?threshold Which thresholding method should be used, "otsu" or "phansalkar"numWindows Number of windows to use for thresholding.structures If the image is already segmented, structures can be inserted to enable hierarchi-

cal classification.classifyStructures

Use hierarchical classification. If yes a pixel classifier has to be defined.pixelClassifier

A SVM to classify pixel based on their color values. Needed if hierarchicalclassification should be applied.

ksToExclude These classes are excluded from kernel smoothing.

Details

The kernels smoother improves the classification for cells which are likely to occur in clusters, liketumour cells. The kernel smoothing method can only be applied for two classes. If there are moreclasses only the normal svm without kernel smoothing is applied. Different classes are labeled withdifferent colors in the image.

Page 8: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

8 colorCorrection

Value

A list with

comp1 classes

comp2 Classes, painted in the image, if paint was true

Author(s)

Henrik Failmezger, [email protected]

Examples

t = system.file("extdata", "trainingData.txt", package="CRImage")#read training datatrainingData=read.table(t,header=TRUE)#create classifierclassifier=createClassifier(trainingData)[[1]]#classify cellsf = system.file("extdata", "exImg.jpg", package="CRImage")classesValues=classifyCells(classifier,filename=f,KS=TRUE,maxShape=800,minShape=40,failureRegion=2000)

colorCorrection Color transfer between images.

Description

The colors of one image are adapted to the colors of a target image.

Usage

colorCorrection(imgO, meanStdTarget,whiteMask = c())

Arguments

imgO The image who’s colors should be adapted

meanStdTarget Array with mean and standard deviation of the target image.

whiteMask Boolean mask of white pixel in the image. These pixels are excluded from colorcorrection.

Details

Mean and standard deviation of the target image can be calculated using the function calculate-MeanStdTarget.

Value

The image with adapted colors.

Author(s)

Henrik Failmezger, [email protected]

Page 9: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

convertHSVToRGB 9

References

Reinhard, E.; Adhikhmin, M.; Gooch, B.; Shirley, P.; , "Color transfer between images," ComputerGraphics and Applications, IEEE , vol.21, no.5, pp.34-41, Sep/Oct 2001 doi: 10.1109/38.946629URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=946629&isnumber=20481

See Also

calculateMeanStandardTarget

Examples

#read the target imagef1= system.file("extdata", "exImg2.jpg", package="CRImage")targetImage=readImage(f1)#read the image whose color values should be adaptedf2= system.file("extdata", "exImg3.jpg", package="CRImage")imgToConvert=readImage(f2)#calculate mean and standard deviation of target color channelsmst=calculateMeanStdTarget(targetImage)# create a white pixel maskwhitePixelMask=imgToConvert[,,1]>0.85 & imgToConvert[,,2]>0.85 & imgToConvert[,,3]>0.85#adapt color channels of imageimgCorrected=colorCorrection(imgToConvert,mst,whitePixelMask)

convertHSVToRGB Conversion from HSV color space to RGB color space

Description

The function converts images in the HSV colour space to the RGB colour space.

Usage

convertHSVToRGB(imgHSV)

Arguments

imgHSV An ’Image’ object or an array in the HSV colour space.

Details

Standard colour space conversion.

Value

An array in the RGB colour space.

Author(s)

Henrik Failmezger, [email protected]

Page 10: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

10 convertLABToRGB

See Also

convertRGBToHSV convertRGBToLAB convertLABToRGB

Examples

f= system.file("extdata", "exImg.jpg", package="CRImage")img=readImage(f)#conversion to RGB color spaceimgRGB=convertHSVToRGB(img)

convertLABToRGB Conversion of LAB colour space to RGB colour space

Description

Color space conversion.

Usage

convertLABToRGB(imgLAB)

Arguments

imgLAB LAB channel vectors.

Details

Color space conversion

Value

RGB channel vectors.

Author(s)

Henrik Failmezger, [email protected]

Examples

f= system.file("extdata", "exImg.jpg", package="CRImage")img=readImage(f)#conversion to HSV color spaceimgRGB=convertLABToRGB(img)

Page 11: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

convertRGBToHSV 11

convertRGBToHSV Conversion from RGB color space to HSV color space

Description

The RGB Image is converted to an HSV image.

Usage

convertRGBToHSV(img)

Arguments

img The RGB image

Details

The entries of the array are Hue, Saturation and Value.

Value

The image in HSV color space.

Author(s)

Henrik Failmezger, [email protected]

See Also

convertHSVToRGB convertRGBToLAB convertLABToRGB

Examples

f= system.file("extdata", "exImg.jpg", package="CRImage")img=readImage(f)#conversion to HSV color spaceimgHSV=convertRGBToHSV(img)

convertRGBToLAB Converts RGB to LAB color space.

Description

Conversion of Color spaces.

Usage

convertRGBToLAB(imgT)

Arguments

imgT The RGB image.

Page 12: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

12 correctCopyNumber

Details

Color space conversion

Value

The image in LAB color space.

Author(s)

Henrik Failmezger, [email protected]

Examples

f= system.file("extdata", "exImg.jpg", package="CRImage")img=readImage(f)#conversion to LAB color spaceimgLAB=convertRGBToLAB(img)

correctCopyNumber Allelic Copy Number correction for cellularity

Description

This function segments copy number and corrects log-ratios (LRR) and beta allele frequencies(BAF) values for cellularity.

Usage

correctCopyNumber(arr="Sample1", chr=NULL, p=NULL, z=NULL, min.value=-5)

Arguments

arr Name of the array.

chr Chromosome to run. If NULL, all chromosomes are run.

p Percentage of tumoural cells.

z Copy Number Data. Must be a dataframe with the following columns: Name(id of the probe), Chr (chromosome), Pos (position), LRR (log ratios) and BAF(beta allele frequencies).

min.value Value assigned to the probes that have 0 copies after correction.

Details

The data.frame z must contain only SNP probes, that is probes with both LRR and BAF values. It isrecommended that all replicated probes are merged so the positions are unique. This function callsDNAcopy to segment the LRR and then correct the segmented profiles for normal contaminationaccording to the method described in the reference below (see for details).

Page 13: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

createBinaryImage 13

Value

A list with 2 components:

y a data.frame with as many rows as probes containing the following variables:Chrom (chromosome), Pos (position), Orig.LRR (LRR before correction) Orig.BAF(BAF before correction), Corr.LRR (LRR after cellularity correction) and Corr.BAF(BAF after correction)

seg a data.frame with the segmented data. Contains the following columns: ID(name of the array), chrom (chromosome), loc.start (start of the region), loc.end(end of the region), num.mark (number of probes in the region), seg.mean (LRRof the region), BAF (BAF of the regions), num.BAF (number of SNP probes inthe region), Sa (estimated absolute copy number for the first allele), Sb (esti-mated absolute copy number for the first allele), LRR.tum (corrected LRR forthe region), BAF.tum (corrected BAF for the region).

Note

Includes an adaptation of aCGH mergeLevels function to fix a problem with ansari.test.

Author(s)

Oscar M. Rueda, [email protected]

References

Yuan, Y et al. Quantitative image analysis of cellular heterogeneity in primary breast tumors en-riches genomic assays. In prep.

Examples

LRR <- c(rnorm(100, 0, 1), rnorm(10, -2, 1), rnorm(20, 3, 1),rnorm(100,0, 1))

BAF <- c(rnorm(100, 0.5, 0.1), rnorm(5, 0.2, 0.01), rnorm(5, 0.8, 0.01), rnorm(10, 0.25, 0.1), rnorm(10, 0.75, 0.1),rnorm(100,0.5, 0.1))

Pos <- sample(x=1:500, size=230, replace=TRUE)Pos <- cumsum(Pos)Chrom <- rep(1, length(LRR))z <- data.frame(Name=1:length(LRR), Chrom=Chrom, Pos=Pos, LRR=LRR, BAF=BAF)res <- correctCopyNumber(arr="Sample1", chr=1, p=0.75, z=z)

createBinaryImage Thresholding

Description

Creates a binary image from a grayscale image by thresholding.

Usage

createBinaryImage(imgG,img=NULL,method="otsu",threshold=NULL,numWindows=1,whitePixelMask=c())

Page 14: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

14 createBinaryImage

Arguments

img An Image object or an array.

imgG The grey valued Image object.

method Either "otsu" or "phansalkar"

threshold Fixed threshold

numWindows Number of windows to use for threshold calculation.

whitePixelMask Boolean mask of white pixels, if they should be excluded from thresholding

Details

The functions returns the binary image resulting from the thresholding. If threshold is defined, allpixels smaller than this value will be fixed to 1 all other values will be set to 0. If threshold is unde-fined, the thresholding value is calculated automatically using ’otsu’ or ’phansalkar’ thresholding.

The function ’otsu’ does Otsu thresholding on the grey level histograms of the image. The function’phansalkar’ does thresholding using the mean and standard deviation of a specified window. Thethresholding is done on the RGB as well as the LAP color space and the results are ORed. Thewindow size is dim(img)/numWindows. White pixel can be excluded from thresholding (e.g. ifwhite is background) by defining a whitePixelMask

Value

The binary image.

Author(s)

Henrik Failmezger, [email protected]

References

Neerad Phansalkar, Sumit More, Ashish Sabale, Dr. Madhuri Joshi, "Adaptive Local Thresholdingfor Detection of Nuclei in Diversly Stained Cytology Images," 2011 IEEE International Conferencein Communications and Signal Processing (ICCSP), pp. 218, 10 Feb. 2011

Nobuyuki Otsu: A threshold selection method from grey level histograms. In: IEEE Transactionson Systems, Man, and Cybernetics. New York 9.1979, S.62-66. ISSN 1083-4419

Examples

f= system.file("extdata", "exImg.jpg", package="CRImage")img=readImage(f)#conversion to grayscaleimgG=EBImage::channel(img,"gray")imgB=createBinaryImage(imgG,img=img,method="otsu",numWindows=4)#white pixel maskwhitePixelMask=img[,,1]>0.85 & img[,,2]>0.85 & img[,,3]>0.85#exclude white pixels from thresholdingimgB=createBinaryImage(imgG,img=img,method="otsu",numWindows=4,whitePixelMask)#phansalkar thresholdimgB=createBinaryImage(imgG,img=img,method="phansalkar",numWindows=4)

Page 15: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

createClassifier 15

createClassifier Construction of a classifier

Description

Creates a classifier for a training set.

Usage

createClassifier(trainingData, cross = FALSE)

Arguments

trainingData A table, created by segmentImage with manually added classes.

cross Does 10-fold cross validation to test the classifiers performance.

Details

Topological features include the density of cells and the size of the surrounding cytoplasma of acell. These features depend on the size of the image. If training image and the image to classifyhave different size, these features can fool the classification and should not be enabled.

Value

A List containing:

classifier The classifier

performance cross validation performance

Author(s)

Henrik Failmezger, [email protected]

See Also

’createTrainingSet’,’classifyCells’

Examples

f = system.file("extdata", "trainingData.txt", package="CRImage")#read training datatrainingData=read.table(f,header=TRUE)#create classifierclassifier=createClassifier(trainingData)[[1]]

Page 16: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

16 labelCells

labelCells Interactive Session for cell labeling

Description

The functions creates an interactive session in order to label cells with their classes. The labeledcells can be used as training set for the classifier. Note!! This is until now only tested for MacOsX.

Usage

labelCells(img, segmentedImage, classes, classColours, nblocks = 3, labeledPoints = NULL, filename = NULL, filenameImage = NULL,transformCoordinates=FALSE)

Arguments

img The image.

segmentedImage The segmented image.

classes The possible class labels.

classColours The colors for the class labels.

nblocks The image can be separated in several blocks, as zooming is not possible.

labeledPoints Labeled cells from a previous training session.

filename The table of labeled cells is saved at this location.

filenameImage The image with the labeled cells is saved at this location.transformCoordinates

deprecated

Details

Use the keys: a: In order to add a label to a cell. d: In order to delete a label from a cell. c: Toswitch between classes. q: To quit the interactive session. r: To refresh the session (labeled cellswill be shown after refreshing)

Value

A table with columns: index: the index of the cell in the segmented image. x: x-coordinate ofthe cell y: y-coordinate of the cell classCell: Label of the cell xLocal: Local x coordinate in thesubimage(block) yLocal: Local y coordinate in the subimage(block) block: Block number in whichthe cell arises.

Author(s)

Henrik Failmezger

Examples

##---- Should be DIRECTLY executable !! ----##-- ==> Define data, use random,##--or do help(data=index) for the standard data sets.

## The function is currently defined as

Page 17: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

plotCorrectedCN 17

plotCorrectedCN Plot CN profiles corrected for cellularity

Description

This function takes the result of a call to correctCopyNumber and plots the results.

Usage

plotCorrectedCN(CN, chr=NULL)

Arguments

CN object result of a call to correctCopyNumber.

chr chromosome to plot.

Details

A panel with four plots is created. The top panel shows LRR (with DNAcopy segmentation over-layed) and BAF before correction and the bottom panel shows the plots after correction.

Value

No value is returned.

Author(s)

Oscar M. Rueda, [email protected]

References

Yuan, Y et al. Quantitative image analysis of cellular heterogeneity in primary breast tumors en-riches genomic assays. In prep.

Examples

LRR <- c(rnorm(100, 0, 1), rnorm(10, -2, 1), rnorm(20, 3, 1),rnorm(100,0, 1))

BAF <- c(rnorm(100, 0.5, 0.1), rnorm(5, 0.2, 0.01), rnorm(5, 0.8, 0.01), rnorm(10, 0.25, 0.1), rnorm(10, 0.75, 0.1),rnorm(100,0.5, 0.1))

Pos <- sample(x=1:500, size=230, replace=TRUE)Pos <- cumsum(Pos)Chrom <- rep(1, length(LRR))z <- data.frame(Name=1:length(LRR), Chrom=Chrom, Pos=Pos, LRR=LRR, BAF=BAF)res <- correctCopyNumber(arr="Sample1", chr=1, p=0.75, z=z)plotCorrectedCN(res, chr=1)

Page 18: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

18 processAperio

processAperio Cellularity Calculation of Aperio TX Scanner

Description

Procession of Aperio TX Slides.

Usage

processAperio(classifier=classifier,inputFolder=inputFolder,outputFolder=outputFolder,identifier=identifier,numSlides=numSlides,cancerIdentifier=cancerIdentifier,classOther = NA,maxShape=800,minShape=40,failureRegion=2000,slideToProcess=NA,KS=TRUE,colors=c(),classesToExclude=c(),threshold="otsu",numWindows=2,colorCorrection=FALSE,classifyStructures=FALSE,ksToExclude=c(),pixelClassifier=NA,densityToExclude=c(),numDensityWindows=32,resizeFactor=4,plotCellTypeDensity=TRUE,greyscaleImage=0,penClassifier=NULL,referenceHist=NULL,fontSize = 10)

Arguments

classifier The classifier.

inputFolder The path to the image folder.

outputFolder The path to the output folder.

identifier The identifier of the files ("Ss" or "Da")

numSlides The number of sections in the image.cancerIdentifier

The identifier of the cancer class

classOther deprecated

maxShape Maximum size of cell nuclei

minShape Minimum size of cell nuclei

failureRegion minimum size of failure regions

slideToProcess Set this parameter if only a certain slide should be processed

KS Apply Kernel Smoother?

colors Colors to paint the classesclassesToExclude

Which class should be excluded?

threshold Which thresholding method should be used, "otsu" or "phansalkar" possible

numWindows Number of windows to use for thresholding.colorCorrection

deprecatedclassifyStructures

Use hierarchical classification. If yes a pixel classifier has to be defined.

ksToExclude These classes are excluded from kernel smoothing.pixelClassifier

A SVM to classify pixel based on their color values. Needed if hierarchicalclassification should be applied.

densityToExclude

This class is excluded from cellularity calculation.numDensityWindows

Number of windows for the density plot.

Page 19: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

processAperio 19

resizeFactor Specifies the size of the cell density image. If this variable is not defined, thesize of the thumbnail is used for the cell density image, else the size is calculatedby size(thumbnail)*resizeFactor. The thumbnail is the small overview image,created by the Aperio software.

plotCellTypeDensity

Plot the density of different cell types?

greyscaleImage Color channel of the RGB image that should be used for thresholding

penClassifier Classifier to exclude low quality images (will be part of next release)

referenceHist Colour Histogram of a reference image that can be used to calculate the qualityof the recent image. (will be part of next release)

fontSize will be part of next release

Details

The function processes images of Aperio TX scanners. The images have to be saved in the CWSformat.

Value

Four folders are created in the output folder.

Files Cellularity values and cell numbers are saved in the fileclassifiedImage

Subimages with labeled tumour and non tumour cells

tumourDensity Cancer heatmaps for every subimagecellCoordinates

Coordinates and cell class for every cell in the subimage

resizeFactor Size of the cellularity density image, calculated by size(thumbnail) * resizeFac-tor. Whereas the thumbnail is the small overview image produced by Aperio.

Author(s)

Henrik Failmezger, [email protected]

Examples

#t = system.file("extdata", "trainingData.txt", package="CRImage")#read training data#trainingData=read.table(t,header=TRUE)#create classifier#classifier=createClassifier(trainingData,topo=FALSE)[[1]]#classify aperio#f = system.file("extdata", package="CRImage")#f=file.path(f,"8905")#dir.create("AperiOutput")#takes long time!

f = system.file("extdata", package="CRImage")fc=file.path(f,"testClassifier")load(fc)fp=file.path(f,"pixelClassifier")load(fp)pixelClassifier=model

Page 20: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

20 SauvolaThreshold

pathToImage=file.path(f,"8905")

pathToOutput="" #specify an output folder here

#processAperio(classifier=classifier,inputFolder=pathToImage,outputFolder=pathToOutput,identifier="Da",numSlides=1,cancerIdentifier="c",maxShape=800,minShape=40,failureRegion=2000,slideToProcess=1,KS=FALSE,colors=c("white","green","blue","brown"),classesToExclude=c('a','l','nl'),threshold="otsu",ksToExclude=c('l','nl'),pixelClassifier=pixelClassifier,classifyStructures=TRUE,densityToExclude=c('a'),numDensityWindows=8,resizeFactor=1.5,plotCellTypeDensity=FALSE,greyscaleImage=1)

SauvolaThreshold Do Sauvola thresholding

Description

Thresholding method using mean and standard deviation.

Usage

SauvolaThreshold(allGreyValues)

Arguments

allGreyValues Vector of gray values.

Details

A threshold for the gray values is returned

Value

The threshold.

Author(s)

Henrik Failmezger, [email protected]

References

J. Sauvola, M. Pietikainen, "Adaptive Document Image Binarization," Pattern Recognition, vol. 33,225-236, 2000

See Also

createBinaryImage

Examples

f1= system.file("extdata", "exImg2.jpg", package="CRImage")print(f1)img=readImage(f1)print(img)#convert to grayscaleimgG=EBImage::channel(img,'grey')#threshold valuet=SauvolaThreshold(as.vector(imgG))

Page 21: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

segmentImage 21

segmentImage Segmentation of an image

Description

The function segments cells or cell nuclei in the image.

Usage

segmentImage(filename="",image=NA,maxShape=NA,minShape=NA,failureRegion=NA,threshold="otsu",numWindows=2, colorCorrection=FALSE, classifyStructures=FALSE,pixelClassifier=NULL,greyscaleImage=0,penClassifier=NULL,referenceHist=NULL)

Arguments

filename A path to an image

image An ’image’ object, if no filename is specified.

maxShape Maximum size of cell nuclei

minShape Minimum size of cell nuclei

failureRegion minimum size of failure regions

threshold Thresholding method, "otsu" or "phansalkar"

numWindows Number of windows to use for thresholding.colorCorrection

deprecatedclassifyStructures

Segment structures in the image, if yes a pixel classifier has to be definedpixelClassifier

A SVM which classifies RGB color values in foreground and background.

greyscaleImage Channel of the RGB image, to use for thresholding, if 0 use a joined greyscaleimage.

penClassifier Classifier to exclude low quality images(will be part of next release)

referenceHist Color histogram of a reference image, that can be used to estimate the quality ofthe recent image (will be part of next release)

Details

The image is converted to greyscale and thresholded. Clutter is deleted using morphological oper-ations. Clustered objects are separated using watershed algorithm. Segmented Cell nuclei, whichexceed the maximum size are thresholded and segmented again. Cell nuclei which fall below theminimum size are deleted. Dark regions which exceed the parameter failureRegion are consideredas artefacts and deleted. If the parameters are not defined, the operations will not be executed.Features are generated for every segmented object.

Value

A list is returned containing

image The original imagesegmented image

The segmented image

Page 22: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

22 segmentImage

Author(s)

Henrik Failmezger, [email protected]

References

EBImage, ’http://www.bioconductor.org/packages/release/bioc/html/EBImage.html’

Examples

#segment image#f = system.file('extdata' ,'exImg.jpg',package='CRImage')#segmentationValues=segmentImage(f,maxShape=800,minShape=40,failureRegion=2000,threshold="otsu",numWindows=4)#image=segmentationValues[[1]]#segmentedImage=segmentationValues[[2]]#imageFeatures=segmentationValues[[3]]

Page 23: Package ‘CRImage’ - BioconductorPackage ‘CRImage’ February 25, 2020 Type Package Title CRImage a package to classify cells and calculate tumour cellularity Version 1.34.0 Date

Index

∗Topic misccalculateCellularity, 3calculateMeanStdTarget, 5calculateOtsu, 6classifyCells, 7colorCorrection, 8convertHSVToRGB, 9convertLABToRGB, 10convertRGBToLAB, 11correctCopyNumber, 12createBinaryImage, 13createClassifier, 15CRImage-package, 2labelCells, 16plotCorrectedCN, 17processAperio, 18SauvolaThreshold, 20segmentImage, 21

calculateCellularity, 3calculateMeanStdTarget, 5calculateOtsu, 6classifyCells, 7colorCorrection, 8convertHSVToRGB, 9convertLABToRGB, 10convertRGBToHSV, 11convertRGBToLAB, 11correctCopyNumber, 12createBinaryImage, 13createClassifier, 15CRImage (CRImage-package), 2CRImage-package, 2

labelCells, 16

plotCorrectedCN, 17processAperio, 18

SauvolaThreshold, 20segmentImage, 21

23