Java Code Examples for ij.process.ByteProcessor#getBufferedImage()
The following examples show how to use
ij.process.ByteProcessor#getBufferedImage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Picture.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Report the sheet image, or a sub-image of it if rectangle area is specified. * <p> * We use the initial image if it is still available. * Otherwise we use the binary source. * * @param rect rectangular area desired, null for whole image * @return the (sub) image */ public BufferedImage getImage (Rectangle rect) { BufferedImage img = initialImage; if (img == null) { ByteProcessor buffer = getSource(SourceKey.BINARY); img = buffer.getBufferedImage(); } if (rect == null) { return img; } else { return img.getSubimage(rect.x, rect.y, rect.width, rect.height); } }
Example 2
Source File: SheetScanner.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
private BufferedImage getCleanImage () { Picture picture = sheet.getPicture(); ByteProcessor buf = picture.getSource(Picture.SourceKey.NO_STAFF); BufferedImage img = buf.getBufferedImage(); buffer = new ByteProcessor(img); TextsCleaner cleaner = new TextsCleaner(buffer, img.createGraphics(), sheet); cleaner.eraseInters(); // Display for visual check? if (constants.displayTexts.isSet() && (OMR.gui != null)) { sheet.getStub().getAssembly().addViewTab( "Texts", new ScrollImageView(sheet, new ImageView(img) { @Override protected void renderItems (Graphics2D g) { sheet.renderItems(g); // Apply registered sheet renderers } }), new BoardsPane(new PixelBoard(sheet))); } // Keep a copy on disk? if (constants.keepTextsBuffer.isSet()) { ImageUtil.saveOnDisk(img, sheet.getId() + ".text"); } return img; }
Example 3
Source File: Picture.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
private ByteProcessor buildNoStaffBuffer () { boolean linesErased = false; ByteProcessor src = getSource(SourceKey.BINARY); ByteProcessor buf = (ByteProcessor) src.duplicate(); BufferedImage img = buf.getBufferedImage(); Graphics2D g = img.createGraphics(); g.setColor(Color.WHITE); for (SystemInfo system : sheet.getSystems()) { for (Staff staff : system.getStaves()) { for (LineInfo li : staff.getLines()) { StaffLine line = (StaffLine) li; Glyph glyph = line.getGlyph(); if (glyph == null) { logger.warn("glyph is null for line " + line + " staff:" + staff); } else { if (glyph.getRunTable() == null) { logger.warn("glyph runtable is null"); } else { glyph.getRunTable().render(g, glyph.getTopLeft()); linesErased = true; } } } } } g.dispose(); if (!linesErased) { logger.warn("No system lines to build NO_STAFF buffer"); // Should not happen! return null; } return new ByteProcessor(img); }
Example 4
Source File: SymbolsFilter.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Start from the staff-free image, remove all good inters, and from the remaining * pixels build the symbols glyphs put in SYMBOL group. * <p> * For not good inters (some "weak" inters have already survived the first REDUCTION step) * we put them aside as optional glyphs that can take part of the symbols glyphs clustering and * thus compete for valuable compounds. * * @param optionalsMap (output) all weak glyphs gathered per system */ public void process (Map<SystemInfo, List<Glyph>> optionalsMap) { logger.debug("SymbolsFilter running..."); ByteProcessor rawBuf = sheet.getPicture().getSource(Picture.SourceKey.NO_STAFF); BufferedImage img = rawBuf.getBufferedImage(); ByteProcessor buffer = new ByteProcessor(img); // Prepare the ground for symbols retrieval, noting optional (weak) glyphs per system Graphics2D g = img.createGraphics(); SymbolsCleaner eraser = new SymbolsCleaner(buffer, g, sheet); eraser.eraseInters(optionalsMap); buffer.threshold(127); // Keep a copy on disk? if (constants.keepSymbolsBuffer.isSet()) { ImageUtil.saveOnDisk(img, sheet.getId() + ".sym"); } // Display for visual check? if (constants.displaySymbols.isSet() && (OMR.gui != null)) { sheet.getStub().getAssembly().addViewTab( "Symbols", new ScrollImageView(sheet, new MyView(img, optionalsMap)), new BoardsPane(new PixelBoard(sheet))); } buildSymbolsGlyphs(buffer); }
Example 5
Source File: SheetDiff.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
MyView (ByteProcessor filtered) { super(filtered.getBufferedImage()); setModelSize(new Dimension(sheet.getWidth(), sheet.getHeight())); // Inject dependency of pixel location setLocationService(sheet.getLocationService()); // Listen to all view parameters ViewParameters.getInstance().addPropertyChangeListener( new WeakPropertyChangeListener(this)); }
Example 6
Source File: SheetDiff.java From audiveris with GNU Affero General Public License v3.0 | 4 votes |
/** * Compute ratios related to negative, positive and false positive * pixels computed between input and output images. */ public void computeRatios () { final int total = sheet.getWidth() * sheet.getHeight(); StopWatch watch = new StopWatch("computeRatios"); watch.start("input"); final ByteProcessor source = sheet.getPicture().getSource(Picture.SourceKey.BINARY); final BufferedImage input = source.getBufferedImage(); watch.start("inputCount"); getInputCount(); logger.info( "INPUT count: {} ratio: {}% (out of {} image pixels)", inputCount, String.format("%.1f", (100d * inputCount) / total), total); watch.start("output"); output = getOutput(); watch.start("xor"); ///BufferedImage xor = ImageUtil.invert(ImageUtil.xor(input, output)); ///ImageUtil.saveOnDisk(xor, sheet.getPage().getId() + ".XOR"); // for (DiffKind kind : DiffKind.values()) { watch.start(kind.toString()); int count = getCount(kind); logger.info( "{}% ({} wrt {} input pixels)", String.format("%15s ratio: %4.1f", kind, (100d * count) / inputCount), count, inputCount); } if (constants.printWatch.isSet()) { watch.print(); } }