java - Algorithm to get all pixels between color border? -
i have long png file containing many sprites in row, width/height changes little bit. however, sprites have fixed blue color 1px border around it.
however, after each sprite, borders connected each other 2px (just border after border interacts) see this:

but @ bottom of sprites, misses 1 pixel point
is there existing algorithm can pixels between color border this, including border when giving pixels?
or other ideas how grab sprites of 1 file , give them fixed size?
i took image , transformed match description.
in plain text went form left right , identify lines might indicate start or end image , used tracker variable decide which.
i approached in java:
import javax.imageio.imageio; import java.awt.image.bufferedimage; import java.awt.image.raster; import java.io.file; import java.io.ioexception; public class pixelartsizefinder { public static void main(string[] args) throws ioexception { file imagefile = new file("pixel_boat.png"); bufferedimage image = imageio.read(imagefile); int w = image.getwidth(); int h = image.getheight(); system.out.format("size: %dx%d%n", w, h); raster data = image.getdata(); int objectsfound = 0; int startobjectwidth = 0; int endobjectwidth = 0; boolean scanningobject = false; (int x = 0; x < w; x++) { boolean verticallinecontainsonlytransparentorborder = true; (int y = 0; y < h; y++) { int[] pixel = data.getpixel(x, y, new int[4]); if (isother(pixel)) { verticallinecontainsonlytransparentorborder = false; } } if (verticallinecontainsonlytransparentorborder) { if (scanningobject) { endobjectwidth = x; system.out.format("object %d: %d-%d (%dpx)%n", objectsfound, startobjectwidth, endobjectwidth, endobjectwidth - startobjectwidth); } else { objectsfound++; startobjectwidth = x; } scanningobject ^= true; //toggle } } } private static boolean istransparent(int[] pixel) { return pixel[3] == 0; } private static boolean isborder(int[] pixel) { return pixel[0] == 0 && pixel[1] == 187 && pixel[2] == 255 && pixel[3] == 255; } private static boolean isother(int[] pixel) { return !istransparent(pixel) && !isborder(pixel); } } and result was
size: 171x72 object 1: 0-27 (27px) object 2: 28-56 (28px) object 3: 57-85 (28px) object 4: 86-113 (27px) object 5: 114-142 (28px) object 6: 143-170 (27px)
Comments
Post a Comment