cs_khammal
Messages postés1Date d'inscriptionmercredi 5 mai 2004StatutMembreDernière intervention 5 mai 2004
-
5 mai 2004 à 11:29
youess81
Messages postés40Date d'inscriptionvendredi 28 mai 2004StatutMembreDernière intervention 5 juin 2005
-
29 juin 2004 à 12:47
Bonjour,
je veux faire la comparaison entre deux images en java (la différence des images)
merci de me résoudre ce problème
cs_tds
Messages postés351Date d'inscriptionmercredi 21 janvier 2004StatutMembreDernière intervention 9 décembre 2004 6 mai 2004 à 07:46
Documente-toi la dessus (javadoc) et tu t'épargneras un sérieux calvaire :p
> ConvolveOp <==
CECI EST EN PLUS PARCE JE SUIS COOL CE MATIN:
*****************************************
Core Java Technologies Tech Tips
Tips, Techniques, and Sample Code
Welcome to the Core Java Technologies Tech Tips for February 17,
2004. Here you'll get tips on using core Java technologies and
APIs, such as those in Java 2 Platform, Standard Edition (J2SE).
This issue covers:
* Loading and Saving Images with the Image I/O Library
* Reflecting JavaBeans Components
These tips were developed using Java 2 SDK, Standard Edition,
v 1.4.2.
This issue of the Core Java Technologies Tech Tips is written by
John Zukowski, president of JZ Ventures, Inc.
(http://www.jzventures.com).
See the Subscribe/Unsubscribe note at the end of this newsletter
to subscribe to Tech Tips that focus on technologies and products
in other Java platforms.
Introduced in J2SE 1.4, the javax.imageio package is the primary
package for the Java Image I/O API. As its name implies, this
package helps you read and write image files. You might wonder
what's so important about this package. The fact is that you
could read images with the getImage method of various classes
like Toolkit and Applet since the initial release of the Java
platform. But there is more to the javax.imageio package than
simply reading images. One important point is that there was no
writeImage or putImage previous to the Image I/O library. Now
there is a way to write images. Also, you can now set properties
such as compression level when you save images.
The first question many people ask when working with the Image
I/O libraries is what formats are supported? With Sun's reference
implementation, you get a specific set. However, the API is
flexible enough so that you can install your own formats by
extending the necessary classes in the javax.imageio.spi
library. For the moment, let's put that aspect of the library
aside. To discover the installed set of readers and writers, you
simply ask the ImageIO class through its getReaderFormatNames()
and getWriterFormatNames() methods (or getReaderMIMETypes() and
getWriterMIMETypes() if you want to work directly with MIME
types). Here's an example:
Basically, you get support for reading GIF, JPEG, and PNG
formatted images, and for writing JPEG and PNGs. There is no GIF
writer provided.
As you work with the Image I/O libraries, you might notice that
almost all the work is requested through the static methods of
the ImageIO class. For basic usage, these static methods are all
you need. For example, to read an image, you pass the location
to one of the following read methods of ImageIO:
o read(File input)
o read(ImageInputStream stream)
o read(InputStream input)
o read(URL input)
The ImageInputStream is an interface of the javax.imageio.stream
package that is seekable, and so it's potentially faster than a
regular InputStream. Instead of getting an InputStream from a
FileInputStream, and passing that InputStream into the read
method, it's more efficient to pass the File object to be read,
or to create a FileImageInputStream from the File. More
specifically, instead of:
InputStream is = new InputStream("myimage.jpg");
ImageIO.read(is);
use either:
File file = new File("myimage.jpg");
ImageIO.read(file);
or
File file = new File("myimage.jpg");
FileImageInputStream fiis =
new FileImageInputStream(file);
ImageIO.read(fiis);
The read method (in all cases) returns a BufferedImage object.
You can then draw this image with the drawImage method of
Graphics, or you can filter it with something like a ConvolveOp
from the java.awt.image package.
The following program, ReadSharp, demonstrates reading and
displaying an image. The program also applies a sharpness filter.
public class ReadSharp {
private static class FrameShower
implements Runnable {
final Frame frame;
public FrameShower(Frame frame) {
this.frame = frame;
}
public void run() {
frame.show();
}
}
public static void main(String args[])
throws IOException {
if (args.length != 1) {
System.err.println(
"Please include image filename on command line");
System.exit(-1);
}
// Read
File file = new File(args[0]);
BufferedImage input = ImageIO.read(file);
// Convert
Kernel sharpKernel =
new Kernel(3, 3, new float[] {
0.0f, -1.0f, 0.0f,
-1.0f, 5.0f, -1.0f,
0.0f, -1.0f, 0.0f
});
ConvolveOp convolveOp =
new ConvolveOp(
sharpKernel, ConvolveOp.EDGE_NO_OP, null);
int width = input.getWidth();
int height = input.getHeight();
BufferedImage output = new BufferedImage(
width, height, BufferedImage.TYPE_INT_ARGB);
convolveOp.filter(input, output);
// Make screen
Icon icon = new ImageIcon(output);
JLabel label = new JLabel(icon);
JFrame frame = new JFrame("Sharp Image");
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(
label, BorderLayout.CENTER);
frame.pack();
// Show
Runnable runner = new FrameShower(frame);
EventQueue.invokeLater(runner);
}
}
When you run the ReadSharp program, specify an image name on the
command line. For example, let's use one of the images from
the February 10, 2004 Tech Tip titled "Styling Digital Images
with ConvolveOp"
(http://java.sun.com/developer/JDCTechTips/2004/tt0210.html):
java ReadSharp BrightnessChanger.jpg
As ReadSharp demonstrates, you don't have to specify the image
format when reading an image. Typically, the system will
determine the correct reader based on the first few bytes of the
stream (typically referred to as the magic number).
Writing images can be just as easy as reading them, though you
can also specify metadata if you need more control. For basic
support, there are the three forms of the write method:
o write(RenderedImage im, String formatName,
File output)
o write(RenderedImage im, String formatName,
ImageOutputStream output)
o write(RenderedImage im, String formatName,
OutputStream output)
All three method forms of the write method return a boolean. This
indicates whether an appropriate writer object is available in
the system. For example, asking for a GIF writer will return
false because there is no GIF writer in the system.
BufferedImage is a type of RenderedImage, so you only need to
pass to the write method the BufferedImage returned by the read
method. This makes it easy to do simple transformations, such as
from GIF to PNG:
File inputFile = new File("image.gif");
BufferedImage input = ImageIO.read(inputFile);
File outputFile = new File("image.png");
ImageIO.write(input, "PNG", outputFile);
Notice that the format name passed to the write method is one of
those returned by getWriterFormatNames().
When you write an image, you can configure various writing
parameter metadata, such as compression level. However, you can't
do that directly with the write method of ImageIO. Instead, you
must use some of the other Image I/O classes (and packages). More
on how to specify this metadata through the ImageWriteParam class
shortly.
It is possible to have more than one Reader or Writer provider
for a specific format. Because of that, methods such as
getImageWritersByFormatName of ImageIO return an Iterator. To
customize output compression levels, you could examine all the
installed providers and find the maximum compression level
supported. Or you could simply use the first one and work with
it. Let's take the simpler approach here:
Iterator iter =
ImageIO.getImageWritersByFormatName("JPG");
if (iter.hasNext()) {
ImageWriter writer = (ImageWriter)iter.next();
...
}
You can get the default writing parameters for a specific
ImageWriter through its getDefaultWriteParam method. The method
returns an ImageWriteParam object. For JPEGs, this is an instance
of javax.imageio.plugins.jpeg.JPEGImageWriteParam (though you
don't need to know this). To change the compression level, you
need to tell the ImageWriteParam object that you want to set the
compression mode explicitly:
Here's a program, Compress, that converts any image that can be
read through the Image I/O library. The program reads the image,
and writes an image for each supported compression format. The
Sun-provided JPEG encoder returns the values of 5%, 75%, and 95%
from getCompressionQualityValues. Notice that the program writes
directly with the ImageWriter object, not with the ImageIO
object.
Because the output parameters are being customized, you must use
an IIOImage object (IIO stands for Image IO) to represent the
image to be written. You can't use a plain BufferedImage. The
BufferedImage can be directly converted to an IIOImage as an
extra step.
youess81
Messages postés40Date d'inscriptionvendredi 28 mai 2004StatutMembreDernière intervention 5 juin 2005 29 juin 2004 à 12:45
pour faire la comparaison entre deux images avant de parler du java ou d'autre langage tu dois savoir qu il existe des alogorithmes qui font la comparaison et cela en se basont sur la notion de detction de contour et par application des Votre texte ici haut puis vous dever utiliser la méthode Votre texte ici qui permet de juger si la comparaison entre 2 motifs ou utilisont tous simplement l'algorithme de intercorrelation si tu veu je peu t'envoyer des doc pour TI
Vous n’avez pas trouvé la réponse que vous recherchez ?
youess81
Messages postés40Date d'inscriptionvendredi 28 mai 2004StatutMembreDernière intervention 5 juin 2005 29 juin 2004 à 12:47
pour faire la comparaison entre deux images avant de parler du java ou d'autre langage tu dois savoir qu il existe des alogorithmes qui font la comparaison et cela en se basont sur la notion de detction de contour et par application des filtre passe haut puis vous dever utiliser la méthode Template Matching tous simplement l'algorithme de intercorrelation si tu veu je peu t'envoyer des doc pour TI