Description Usage Arguments Details Value Author(s) Examples
Calculate the local contrast of an input image for every pixel of the image over a given window centered on that pixel.
1 | calcContrast(image, w_x, w_y, brushShape = "disc", validate = TRUE)
|
image |
A numeric 2D matrix-like on which the contrast should be determined |
w_x |
The size of the window in x-direction |
w_y |
The size of the window in y-direction |
brushShape |
A string indicating the shape of the window. Currently
supported values are |
validate |
A boolean value indicating if the variables need to be validated or if this function is being called internally, i.e. the variables have already been validated once. This is only used to marginally speed up internal calls to functions and has no bearing on the actual functionality of the method. |
The local contrast is calculated for every pixel of image
.
This means that a window is centered around a given pixel and the variance
of the intensity values within this window are determined via
Var = E[X^2] - (E[X])^2.
The brushShape
indicates the shape of the window over which to
calculate the variance. Depending on the symmetry of the objects being
imaged, the window shape may have a significant impact on the quality of
the projection.
A 2D matrix with the same dimensions as image
, which shows
the local contrast at each corresponding pixel of image
.
Jan Sauer
1 |
function (image, w_x, w_y, brushShape = "disc", validate = TRUE)
{
if (missing(image))
stop("'image' is missing")
if (missing(w_x))
stop("'w_x' is missing")
if (missing(w_y))
stop("'w_y' is missing")
if (class(image) == "Image")
image = imageData(image)
if (validate)
valid = validateVariables(image = image, w_x = w_x, w_y = w_y,
brushShape = brushShape)
f = NULL
if (brushShape == "box")
f = matrix(1/((2 * w_x + 1) * (2 * w_y + 1)), nrow = (2 *
w_y + 1), ncol = (2 * w_x + 1))
if (brushShape == "disc") {
f = makeBrush(size = 2 * w_x + 1, shape = "disc", step = TRUE)
f = f/sum(f)
}
imgSquared = image^2
contrast = filter2(x = Image(imgSquared), filter = f, boundary = "replicate") -
filter2(x = Image(image), filter = f, boundary = "replicate")^2
return(contrast)
}
<environment: namespace:MaxContrastProjection>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.