public static void main(String[] args) { LookupTable tbl = createReverseTable(); LookupOp op = new LookupOp(tbl, null); for (ImageType t : ImageType.values()) { System.out.print(t); BufferedImage src = createSourceImage(t); BufferedImage dst = op.filter(src, null); int rgb = dst.getRGB(0, 0); System.out.printf(" Result: 0x%X ", rgb); if (rgb != argbReverse) { throw new RuntimeException("Test failed."); } System.out.println("Passed."); } }
/** * For testing lookup tables */ public static Image toInverseVideo(Image source) { // BufferedImage src = new BufferedImage(source.getWidth(null), source .getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = src.getGraphics(); g.drawImage(source, 0, 0, null); // short[][] lookup = new short[4][256]; for (int c = 0; c < 4; c++) { for (short b = 0; b < 256; b++) { if (c == 3) lookup[c][b] = b; else lookup[c][b] = (short)(255 - b); } } LookupTable table = new ShortLookupTable(0, lookup); LookupOp op = new LookupOp (table, null); return op.filter(src, null); }
private void botonContrasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonContrasteActionPerformed try { VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_SFUNCION); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error en el contraste"); } }
private void botonIluminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonIluminarActionPerformed try { VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_LOGARITHM); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error al iluminar"); } }
private void botonOscurecerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonOscurecerActionPerformed try { VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_POWER); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error al oscurecer"); } }
/** * Crea objetos LookupTable usando valores por defecto */ static LookupTable createLookupTable(int type){ switch(type){ case TYPE_NEGATIVE: return negativeFuction(); case TYPE_SFUNCION: return sFuction(DEFAULT_M_SFUNCTION,DEFAULT_E_SFUNCTION); case TYPE_LOGARITHM: return logarithmFuction(); case TYPE_POWER: return powerFuction(DEFAULT_POWER); case TYPE_ROOT: return rootFuction(DEFAULT_ROOT); case TYPE_GAMMA_CORRECTION: return gammaCorrection(DEFAULT_A_GAMMA,DEFAULT_GAMMA); default: return null; } }
private void botonContrasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonContrasteActionPerformed try { VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_SFUNCION); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error en el contraste"); } }
private void botonIluminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonIluminarActionPerformed try { VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_LOGARITHM); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error al iluminar"); } }
private void botonOscurecerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonOscurecerActionPerformed try { VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_POWER); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error al oscurecer"); } }
private void negativeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_negativeActionPerformed try { VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_NEGATIVE); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null) { vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error en el contraste"); } }
/** * Crea objetos LookupTable usando valores por defecto */ static LookupTable createLookupTable(int type) { switch (type) { case TYPE_NEGATIVE: return negativeFuction(); case TYPE_SFUNCION: return sFuction(DEFAULT_M_SFUNCTION, DEFAULT_E_SFUNCTION); case TYPE_LOGARITHM: return logarithmFuction(); case TYPE_POWER: return powerFuction(DEFAULT_POWER); case TYPE_ROOT: return rootFuction(DEFAULT_ROOT); case TYPE_GAMMA_CORRECTION: return gammaCorrection(DEFAULT_A_GAMMA, DEFAULT_GAMMA); default: return null; } }
/** * Corrección gamma. Si 0 menor_que gamma menor_que 1 ilumina, si * gamma_mayor_que 1 oscurece * * @param cteA double * @param gamma double * @return LookupTable */ public static LookupTable gammaCorrection(double cteA, double gamma) { if (gamma <= 0) { return null; } // K: constante de normalización double K = ((double) MAX_LEVEL) / (cteA * Math.pow(((double) MAX_LEVEL), gamma)); short lt[] = new short[MAX_LEVEL + 1]; for (int l = 0; l <= MAX_LEVEL; l++) { lt[l] = (short) (K * cteA * Math.pow((double) l, gamma)); } ShortLookupTable slt = new ShortLookupTable(0, lt); if (ECHO) { plot(lt); } return slt; }
private void botonContrasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonContrasteActionPerformed try { VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_SFUNCION); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null){ vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error en el contraste"); } }
private void botonIluminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonIluminarActionPerformed try { VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_LOGARITHM); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null){ vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error al iluminar"); } }
private void botonOscurecerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonOscurecerActionPerformed try { VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi != null) { BufferedImage imgActual = convertImageType(vi.getLienzo().getImageActual(), BufferedImage.TYPE_INT_RGB); LookupTable ltp = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_POWER); LookupOp lop = new LookupOp(ltp, null); BufferedImage imgdest = lop.filter(imgActual, null); if (imgdest != null){ vi.getLienzo().setImageOriginal(imgdest); vi.getLienzo().repaint(); } } } catch (Exception e) { System.err.println("Error al oscurecer"); } }
/** * Reverse image color components, leave alpha unchanged. */ private static LookupTable createReverseTable() { byte[] data = new byte[256]; for (int i = 0; i < 256; i++) { data[i] = (byte) (255 - i); } return new ByteLookupTable(0, data); }
public MyRescaleOp( final double scale, final double offset ) { super( new LookupTable( 0, 4 ) { public int[] lookupPixel( int[] src, int[] dest ) { for ( int i = 0; i < src.length; i++ ) { dest[i] = (int) MathUtil.clamp( 0, src[i] * scale + offset, 255 ); } return dest; } }, null ); }
private static BufferedImage colorExtractChannel(BufferedImage src, BufferedImage dest, int channel) { LookupTable lookupTable; switch (channel) { case RED_CHANNEL: lookupTable = LookupFactory.createLookupForOnlyRed(); break; case REMOVE_RED_CHANNEL: lookupTable = LookupFactory.createLookupForRemoveRed(); break; case GREEN_CHANNEL: lookupTable = LookupFactory.createLookupForOnlyGreen(); break; case REMOVE_GREEN_CHANNEL: lookupTable = LookupFactory.createLookupForRemoveGreen(); break; case BLUE_CHANNEL: lookupTable = LookupFactory.createLookupForOnlyBlue(); break; case REMOVE_BLUE_CHANNEL: lookupTable = LookupFactory.createLookupForRemoveBlue(); break; default: throw new IllegalStateException("should not het here"); } BufferedImageOp filterOp = new FastLookupOp((ShortLookupTable) lookupTable); filterOp.filter(src, dest); return dest; }
public static LookupTable createLookupForRemoveRed() { short[][] lookupData = new short[3][256]; lookupData[0] = getNullMapping(); lookupData[1] = getDefaultMapping(); lookupData[2] = getDefaultMapping(); return new ShortLookupTable(0, lookupData); }
public static LookupTable createLookupForOnlyRed() { short[][] lookupData = new short[3][256]; lookupData[0] = getDefaultMapping(); lookupData[1] = getNullMapping(); lookupData[2] = getNullMapping(); return new ShortLookupTable(0, lookupData); }
public static LookupTable createLookupForRemoveGreen() { short[][] lookupData = new short[3][256]; lookupData[0] = getDefaultMapping(); lookupData[1] = getNullMapping(); lookupData[2] = getDefaultMapping(); return new ShortLookupTable(0, lookupData); }
public static LookupTable createLookupForOnlyGreen() { short[][] lookupData = new short[3][256]; lookupData[0] = getNullMapping(); lookupData[1] = getDefaultMapping(); lookupData[2] = getNullMapping(); return new ShortLookupTable(0, lookupData); }
public static LookupTable createLookupForRemoveBlue() { short[][] lookupData = new short[3][256]; lookupData[0] = getDefaultMapping(); lookupData[1] = getDefaultMapping(); lookupData[2] = getNullMapping(); return new ShortLookupTable(0, lookupData); }