MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getPixel

Method getPixel

ij/src/main/java/ij/ImagePlus.java:1810–1860  ·  view source on GitHub ↗

Returns the pixel value at (x,y) as a 4 element array. Grayscale values are retuned in the first element. RGB values are returned in the first 3 elements. For indexed color images, the RGB values are returned in the first 3 three elements and the index (0-255) is returned in the last.

(int x, int y)

Source from the content-addressed store, hash-verified

1808 first 3 three elements and the index (0-255) is returned in the last.
1809 */
1810 public int[] getPixel(int x, int y) {
1811 pvalue[0]=pvalue[1]=pvalue[2]=pvalue[3]=0;
1812 switch (imageType) {
1813 case GRAY8: case COLOR_256:
1814 int index;
1815 if (ip!=null)
1816 index = ip.getPixel(x, y);
1817 else {
1818 byte[] pixels8;
1819 if (img==null) return pvalue;
1820 PixelGrabber pg = new PixelGrabber(img,x,y,1,1,false);
1821 try {pg.grabPixels();}
1822 catch (InterruptedException e){return pvalue;};
1823 pixels8 = (byte[])(pg.getPixels());
1824 index = pixels8!=null?pixels8[0]&0xff:0;
1825 }
1826 if (imageType!=COLOR_256) {
1827 pvalue[0] = index;
1828 return pvalue;
1829 }
1830 pvalue[3] = index;
1831 // fall through to get rgb values
1832 case COLOR_RGB:
1833 if (ip!=null && ip.getNChannels()==1) {
1834 pvalue[0] = ip.getPixel(x, y);
1835 return pvalue;
1836 }
1837 int c = 0;
1838 if (imageType==COLOR_RGB && ip!=null)
1839 c = ip.getPixel(x, y);
1840 else {
1841 int[] pixels32 = new int[1];
1842 if (img==null) return pvalue;
1843 PixelGrabber pg = new PixelGrabber(img, x, y, 1, 1, pixels32, 0, width);
1844 try {pg.grabPixels();}
1845 catch (InterruptedException e) {return pvalue;};
1846 c = pixels32[0];
1847 }
1848 int r = (c&0xff0000)>>16;
1849 int g = (c&0xff00)>>8;
1850 int b = c&0xff;
1851 pvalue[0] = r;
1852 pvalue[1] = g;
1853 pvalue[2] = b;
1854 break;
1855 case GRAY16: case GRAY32:
1856 if (ip!=null) pvalue[0] = ip.getPixel(x, y);
1857 break;
1858 }
1859 return pvalue;
1860 }
1861
1862 /** Returns an empty image stack that has the same
1863 width, height and color table as this image. */

Callers 11

getValueAsStringMethod · 0.95
getRGBLutTableMethod · 0.95
replicate_decodeMethod · 0.45
average_decodeMethod · 0.45
smooth_decodeMethod · 0.45
adaptive_decodeMethod · 0.45
replicate_decodeMethod · 0.45
average_decodeMethod · 0.45
smooth_decodeMethod · 0.45
adaptive_decodeMethod · 0.45
setValueTextFieldMethod · 0.45

Calls 2

getPixelsMethod · 0.45
getNChannelsMethod · 0.45

Tested by

no test coverage detected