001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package org.openimaj.docs.tutorial.fund.images.firstimage;
031
032import java.io.IOException;
033import java.net.URL;
034
035import org.openimaj.image.DisplayUtilities;
036import org.openimaj.image.ImageUtilities;
037import org.openimaj.image.MBFImage;
038import org.openimaj.image.colour.RGBColour;
039import org.openimaj.image.processing.edges.CannyEdgeDetector;
040import org.openimaj.image.typography.hershey.HersheyFont;
041import org.openimaj.math.geometry.shape.Ellipse;
042
043/**
044 * OpenIMAJ Hello world!
045 * 
046 */
047public class App {
048        /**
049         * Main method
050         * 
051         * @param args
052         * @throws IOException
053         */
054        public static void main(String[] args) throws IOException {
055                // Load the image
056                final MBFImage image = ImageUtilities.readMBF(new URL("http://static.openimaj.org/media/tutorial/sinaface.jpg"));
057
058                // Print colour space
059                System.out.println(image.colourSpace);
060
061                // Display the image
062                DisplayUtilities.display(image);
063                DisplayUtilities.display(image.getBand(0), "Red Channel");
064
065                // Set blue and green pixels to black, and draw
066                final MBFImage clone = image.clone();
067                for (int y = 0; y < image.getHeight(); y++) {
068                        for (int x = 0; x < image.getWidth(); x++) {
069                                clone.getBand(1).pixels[y][x] = 0;
070                                clone.getBand(2).pixels[y][x] = 0;
071                        }
072                }
073                DisplayUtilities.display(clone);
074
075                // Find edges
076                image.processInplace(new CannyEdgeDetector());
077                DisplayUtilities.display(image);
078
079                // Draw some stuff
080                image.drawShapeFilled(new Ellipse(700f, 450f, 20f, 10f, 0f), RGBColour.WHITE);
081                image.drawShapeFilled(new Ellipse(650f, 425f, 25f, 12f, 0f), RGBColour.WHITE);
082                image.drawShapeFilled(new Ellipse(600f, 380f, 30f, 15f, 0f), RGBColour.WHITE);
083                image.drawShapeFilled(new Ellipse(500f, 300f, 100f, 70f, 0f), RGBColour.WHITE);
084                image.drawText("OpenIMAJ is", 425, 300, HersheyFont.ASTROLOGY, 20, RGBColour.BLACK);
085                image.drawText("Awesome", 425, 330, HersheyFont.ASTROLOGY, 20, RGBColour.BLACK);
086                DisplayUtilities.display(image);
087        }
088}