java - Converting a double scripted array of grayscale int values to a BufferedImage -
so after hours of searching ready pull hair out on one.
i doing research in computer vision , working grayscale images. need end "image" (a double scripted double array) of sobel filtered double values. sobel converter set take in double scripted int array (int[][]) , go there.
i reading in buffered image , gather grayscale int values via method 99% sure works (i can present if need be).
next attempting convert matrix of int values bufferedimage below method:
private bufferedimage getbifromintarr(int[][] matrix){ bufferedimage img = new bufferedimage(matrix.length * 4, matrix[0].length, bufferedimage.type_int_argb); - gather pixels in form of [alpha, r, g, b] - multiply size of array 4 model int[] pixels = new int[(matrix.length * 4 * matrix[0].length)]; int index = 0; (int = 0; < matrix.length; i++) { (int j = 0; j < matrix[0].length; j++) { int pixel = matrix[i][j]; pixels[index] = pixel; index++; (int k = 0; k < 3; k++) { pixels[index] = 0; index++; } } } -get raster writableraster raster = img.getraster(); -output amount of pixels , sample of array system.out.println(pixels.length); (int = 0; < pixels.length; i++) { system.out.print(pixels[i] + " "); } - set pixels of raster raster.setpixels(0, 0, matrix.length, matrix[0].length, pixels); - paint image via external routing check works (does not) p.panel.setnewimage(img); return img; } here understanding. argb type consists of 4 values alpha, red, green, , blue. guessing setting alpha values in new bufferedimage greyscale image int values (the matrix values passed in) reproduce image. please correct me if wrong. can see create array of pixels stores int values this: [intvalue, 0, 0, 0] repeatedly try stay 4 value model.
then create writable raster , set gathered pixels in using gathered pixels. thing nothing in bufferedimage. no error code below , im sure indeces correct.
what doing wrong? im sure obvious appreciated because cant see it. perhaps assumption model wrong?
thanks, chronic
Comments
Post a Comment