Merge four CMYK images into one RGB Image Java -
thanks in advance provide me, , sorry bad english.
i know there's lot of questions topic, have looked lot on internet (and stackoverflow too) haven't found answer this...
i have 4 images; each 1 of them in type_byte_gray color model. have loaded these 4 images using code:
int numelems = 4; bufferedimage[] img = new bufferedimage[numelems]; for(int i=0;i<numelems;i++){ fileinputstream in = new fileinputstream(args[i]); img[i] = imageio.read(in); in.close(); } just imageio read... need "merge" 4 images 1 rgb image... each 1 of images 1 channel cmyk image. these images have equal dimensions. have converted 4 images 1 cmyk image using code:
for(int j=0;j<img[0].getheight();j++){ //read current point color... for(int k=0;k<numelems;k++){ colpunto[k] = (img[k].getrgb(i, j) & 0xff); } int colorpunto = convertcomponentsrgb(colpunto); //now, set point... out.setrgb(i, j, colorpunto); } } this function "convertcomponentsrgb" natural math convert cmyk color rgb color...
function convertcomponentsrgb(int[] pointcolor){ float cyan = (float)pointcolor[0] / (float)255; float magenta = (float)pointcolor[1] / (float)255; float yellow = (float)pointcolor[2] / (float)255; float black = (float)pointcolor[3] / (float)255; float c = min(1f,cyan * (1f - black) + black); //minimum value float m = min(1f,magenta * (1f - black) + black); //minimum value float y = min(1f, yellow * (1f - black) + black); //minimum value result[0] = math.round(255f*(1f - c)); result[1] = math.round(255f*(1f - m)); result[2] = math.round(255f*(1f - y)); return (result[0]<<16) | (result[1]<<8) | result[2]; } the problem here is... speed. takes 12 seconds process 1 image, because we've read each pixel , write each pixel, , think "getrgb" , "setrgb" functions aren't quick (or, it's best way achieve this).
¿how can achieve this? have reading lot colormodel, filters, still don't understand how achieve in better time.
you can use getdata , setdata speed access pixels vs. getrgb , setrgb.
there's no need convert cmyk floating point , back, can work directly pixel values:
function convertcomponentsrgb(int[] pointcolor){ int r = max(0, 255 - (pointcolor[0] + pointcolor[3])); int g = max(0, 255 - (pointcolor[1] + pointcolor[3])); int b = max(0, 255 - (pointcolor[2] + pointcolor[3])); return (r<<16) | (g<<8) | b; }
Comments
Post a Comment