ReplacePixelValue

ReplacePixelValue[image,pposval]

changes the pixel values at pixel position ppos in image to val.

ReplacePixelValue[image,pposval,"type"]

assumes val to be of the specified type.

Details

  • ReplacePixelValue is typically used for image correction or annotation of 2D and 3D images by replacing pixel values at selected positions.
  • ReplacePixelValue assumes a pixel-aligned coordinate system that is shifted by 0.5 to the left and down with respect to the standard image coordinate system.
  • In ReplacePixelValue, integer coordinates correspond to the centers of the pixels. In 2D, pixel position represents the center of the bottom-left pixel. In 3D, pixel position corresponds to the center of the bottom-left front pixel.
  • Pixel positions ppos can be in one of the following forms:
  • {x,y} or {x,y,z}single position in 2D or 3D
    {xmin;;xmax,}span of positions
    {xmin;;xmax;;xstep,}span of positions with steps
    {pos1,pos2,}a list of position specifications
    markerimagea marker image
  • ReplacePixelValue[image,{ppos1->val1,}] can be used to set pixel values for multiple positions.
  • When the pixel position ppos lies on a boundary between pixels, all adjacent pixels are modified.
  • Pixel value val can be in one of the following forms:
  • sa scalar
    colora color
    {s1,s2,}a list of channel values
  • Possible settings for "type" include:
  • "Bit"integer 0 or 1
    "Byte"integer 0 through 255
    "Bit16"integer 0 through 65535
    "Real32"single-precision real (32 bit)
    "Real64"double-precision real (64 bit)
  • ReplacePixelValue typically gives an image that has the same type as image.

Examples

open allclose all

Basic Examples  (3)

Set a pixel in an image:

Replace a list of pixels in an image:

Specify the data type of the replacement value:

Scope  (12)

Data  (4)

Replace a value in a grayscale image:

Replace a value in a color image:

Replace a value in a grayscale 3D image:

Set a pixel in the top-left front corner of a 3D color image to gray:

Position  (6)

Replace a single pixel value:

Replace pixel values at multiple positions:

Replace multiple pixel values:

Use Span to replace multiple pixel values:

Replace all pixels in a row:

Use a marker image to replace pixel values:

Type  (2)

Replace a single pixel value:

Specify the data type of the replacement value:

Applications  (2)

Replace black beans with red beans:

Extract pixel coordinates of handwritten annotations in a document:

Create a binary mask:

Remove the annotations:

Properties & Relations  (3)

Any position within the bounds of a pixel may be used:

When the specified coordinate falls between pixels, all surrounding pixels are modified:

If a position outside of the image bounds is specified, no pixel is modified:

Wolfram Research (2012), ReplacePixelValue, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplacePixelValue.html (updated 2014).

Text

Wolfram Research (2012), ReplacePixelValue, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplacePixelValue.html (updated 2014).

CMS

Wolfram Language. 2012. "ReplacePixelValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/ReplacePixelValue.html.

APA

Wolfram Language. (2012). ReplacePixelValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReplacePixelValue.html

BibTeX

@misc{reference.wolfram_2023_replacepixelvalue, author="Wolfram Research", title="{ReplacePixelValue}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/ReplacePixelValue.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_replacepixelvalue, organization={Wolfram Research}, title={ReplacePixelValue}, year={2014}, url={https://reference.wolfram.com/language/ref/ReplacePixelValue.html}, note=[Accessed: 18-March-2024 ]}