File talk:Ondelette schema de compression.png
Code Java (langage) ayant cervi à la générations des image
[edit]package org.wikipedia;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ColorModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.File;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import com.sun.imageio.plugins.png.PNGImageWriterSpi;
/**
* @author sbrunner
* Create on 6 janv. 2005
*/
public class Ondelettes {
private static final int MULTIPLIER = 2;
public static void main(String s[]) {
BufferedImage bi = open("/home/sbrunner/Desktop/imgstartb.png");
int iw = bi.getWidth();
int ih = bi.getWidth();
save(new OndeOP().filter(bi, new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB)), "/home/sbrunner/Desktop/img-vertical.png");
save(new OndeOP(1).filter(bi, new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB)), "/home/sbrunner/Desktop/img-1.png");
save(new OndeOP(2).filter(bi, new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB)), "/home/sbrunner/Desktop/img-2.png");
save(new OndeOP(-1).filter(bi, new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB)), "/home/sbrunner/Desktop/img-all.png");
}
private static BufferedImage open(String pFileName) {
ImageIcon imageIcon =new ImageIcon(pFileName);
Image img = imageIcon.getImage();
int iw = imageIcon.getIconWidth();
int ih = imageIcon.getIconHeight();
BufferedImage result = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
Graphics2D big = result.createGraphics();
big.drawImage(img,0,0,null);
return result;
}
private static void save(BufferedImage pImage, String pFileName) {
try {
ImageOutputStream out = new FileImageOutputStream(new File(pFileName));
ImageWriter encoder = new PNGImageWriterSpi().createWriterInstance();
encoder.setOutput(out);
encoder.write(pImage);
out.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
private static class OndeOP extends AbstractOP {
int mNbPass;
boolean pDoVertical = true;
public OndeOP(int nbPass) {
mNbPass = nbPass;
}
public OndeOP() {
mNbPass = 1;
pDoVertical = false;
}
public final WritableRaster filter (Raster pSrc, WritableRaster pDst) {
int numBands = pSrc.getNumBands();
int totalLength = pSrc.getWidth();
//int width = pSrc.getWidth();
//int height = pSrc.getHeight();
Raster src = pSrc;
WritableRaster dst = new BufferedImage(totalLength, totalLength, BufferedImage.TYPE_INT_RGB).getRaster();
int length = totalLength;
for (int p = 0 ; (p < mNbPass || mNbPass < 0) && length > 1; p++) {
for (int y=0; y < length; y++) {
for (int x = 0; x < length / 2; x++) {
int[] pix = new int[numBands];
// Get data for all bands at this x,y position
int[] p1 = src.getPixel(2*x, y, new int[numBands]);
int[] p2 = src.getPixel(2*x+1, y, new int[numBands]);
for (int z=0; z<numBands; z++) {
pix[z] = (p1[z] + p2[z]) / 2;
}
// Put it back for all bands
dst.setPixel(x, y, pix);
}
for (int x = 0; x < length / 2; x++) {
int[] pix = new int[numBands];
// Get data for all bands at this x,y position
int[] p1 = src.getPixel(2*x, y, new int[numBands]);
int[] p2 = src.getPixel(2*x+1, y, new int[numBands]);
for (int z=0; z<numBands; z++) {
pix[z] = 255 - MULTIPLIER * Math.abs(p1[z] - p2[z]) / 2;
}
// Put it back for all bands
dst.setPixel(length / 2 + x, y, pix);
}
}
cpNext(src, dst, length);
src = dst;
boolean last = p == mNbPass - 1 || length == 2;
dst = last ? pDst : new BufferedImage(totalLength, totalLength, BufferedImage.TYPE_INT_RGB).getRaster();
if (pDoVertical) {
for (int x = 0; x < length; x++) {
for (int y=0; y < length / 2; y++) {
int[] pix = new int[numBands];
// Get data for all bands at this x,y position
int[] p1 = src.getPixel(x, 2*y, new int[numBands]);
int[] p2 = src.getPixel(x, 2*y+1, new int[numBands]);
for (int z=0; z<numBands; z++) {
pix[z] = (p1[z] + p2[z]) / 2;
}
// Put it back for all bands
dst.setPixel(x, y, pix);
}
for (int y=0; y < length / 2; y++) {
int[] pix = new int[numBands];
// Get data for all bands at this x,y position
int[] p1 = src.getPixel(x, 2*y, new int[numBands]);
int[] p2 = src.getPixel(x, 2*y+1, new int[numBands]);
for (int z=0; z<numBands; z++) {
pix[z] = 255 - MULTIPLIER * Math.abs(p1[z] - p2[z]) / 2;
}
// Put it back for all bands
dst.setPixel(x, length / 2 + y, pix);
}
}
cpNext(src, dst, length);
}
else {
for (int x = 0; x < totalLength; x++) {
for (int y=0; y < totalLength; y++) {
dst.setPixel(x, y, src.getPixel(x, y, new int[numBands]));
}
}
}
length /= 2;
if (!last) {
src = dst;
dst = new BufferedImage(totalLength, totalLength, BufferedImage.TYPE_INT_RGB).getRaster();
}
}
return pDst;
}
private void cpNext(Raster src, WritableRaster dst, int length) {
int numBands = src.getNumBands();
int totalLength = src.getWidth();
for (int x = length; x < totalLength; x++) {
for (int y=0; y < totalLength; y++) {
dst.setPixel(x, y, src.getPixel(x, y, new int[numBands]));
}
}
for (int x = 0; x < length; x++) {
for (int y=length; y < totalLength; y++) {
dst.setPixel(x, y, src.getPixel(x, y, new int[numBands]));
}
}
}
}
private static abstract class AbstractOP implements BufferedImageOp {
public abstract WritableRaster filter (Raster src, WritableRaster dst);
public final BufferedImage filter (BufferedImage src, BufferedImage dst) {
filter(src.getRaster(), dst.getRaster());
return dst;
}
public final Rectangle2D getBounds2D (BufferedImage src) {
return getBounds2D(src.getRaster());
}
public final Rectangle2D getBounds2D (Raster src) {
return src.getBounds();
}
public BufferedImage createCompatibleDestImage (BufferedImage src,
ColorModel destCM) {
return null;
}
public WritableRaster createCompatibleDestRaster (Raster src) {
return src.createCompatibleWritableRaster(src.getWidth(), src.getHeight());
}
public final Point2D getPoint2D (Point2D srcPt, Point2D dstPt) {
if (dstPt == null) {
dstPt = new Point2D.Float();
}
dstPt.setLocation(srcPt.getX(), srcPt.getY());
return dstPt;
}
public final RenderingHints getRenderingHints() {
return null;
}
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" inkscape:export-ydpi="72.000000" inkscape:export-xdpi="72.000000" inkscape:export-filename="/home/sbrunner/Documents/Wikipedia/Ondelet/Ondelette schema de compression.png" sodipodi:docname="Ondelette schema de compression.svg" sodipodi:docbase="/home/sbrunner/Desktop/Documents/Wikipedia/Ondelet" inkscape:version="0.41" sodipodi:version="0.32" id="svg1" height="297mm" width="210mm"> <defs id="defs3" /> <sodipodi:namedview inkscape:window-y="0" inkscape:window-x="0" inkscape:window-height="1114" inkscape:window-width="1592" inkscape:current-layer="layer1" inkscape:cy="701.68457" inkscape:cx="211.11437" inkscape:zoom="1.2095061" inkscape:pageshadow="2" inkscape:pageopacity="0.0" borderopacity="1.0" bordercolor="#666666" pagecolor="#ffffff" id="base" /> <metadata id="metadata4"> <rdf:RDF id="RDF5"> <cc:Work id="Work6" rdf:about=""> <dc:format id="format7">image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" id="type9" /> </cc:Work> </rdf:RDF> </metadata> <g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1"> <path sodipodi:nodetypes="cc" id="path2745" d="M 711.48257,406.82372 C -138.31023,406.82372 -138.31023,406.82372 -138.31023,406.82372" style="fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:#000000;stroke-width:1.2500000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000" /> <g transform="translate(0.000000,0.252069)" id="g3993"> <path transform="translate(-36.48279,99.28104)" sodipodi:nodetypes="cc" id="path2116" d="M -60.752668,131.06956 C 789.04013,131.06956 789.04013,131.06956 789.04013,131.06956" style="fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:#000000;stroke-width:1.2500000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000" /> <path transform="translate(-36.48279,99.28104)" sodipodi:nodetypes="cccc" id="path2118" d="M 778.01219,135.64720 L 789.25322,131.07457 L 789.25322,131.07457 L 778.01219,127.02590" style="fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:#000000;stroke-width:1.2500000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000" /> </g> <rect y="205.33829" x="40.472084" height="51.062733" width="138.15788" id="rect1061" style="fill:#ffffff;fill-opacity:1.0000000;stroke:#000000;stroke-width:0.61658244pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000" /> <text transform="translate(-51.27323,26.49179)" id="text1062" y="202.8515" x="106.46902" style="font-size:12.000000;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;font-family:Bitstream Vera Sans" xml:space="preserve"><tspan y="202.85150" x="106.46902" id="tspan1063" sodipodi:role="line">Transformation en </tspan><tspan y="214.85150" x="106.46902" id="tspan1065" sodipodi:role="line">ondelettes</tspan></text> <rect y="381.29236" x="40.472084" height="51.062733" width="138.15788" id="rect1075" style="fill:#ffffff;fill-opacity:1.0000000;stroke:#000000;stroke-width:0.61658244pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000" /> <text transform="translate(-51.27323,202.4458)" id="text1076" y="202.8515" x="106.46902" style="font-size:12.000000;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;font-family:Bitstream Vera Sans" xml:space="preserve"><tspan y="202.85150" x="106.46902" id="tspan1077" sodipodi:role="line">Transformation en </tspan><tspan y="214.85150" x="106.46902" id="tspan1079" sodipodi:role="line">ondelettes inverse</tspan></text> <rect y="381.29236" x="351.67276" height="51.062733" width="116.98221" id="rect1082" style="fill:#ffffff;fill-opacity:1.0000000;stroke:#000000;stroke-width:0.56736588pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000" /> <text transform="translate(259.9865,202.4458)" id="text1083" y="202.8515" x="106.46902" style="font-size:12.000000;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;font-family:Bitstream Vera Sans" xml:space="preserve"><tspan y="202.85150" x="106.46902" id="tspan1084" sodipodi:role="line">Quantification </tspan><tspan y="214.85150" x="106.46902" id="tspan1442" sodipodi:role="line">inverse</tspan></text> <rect y="212.51469" x="355.01630" height="36.709927" width="110.29516" id="rect1089" style="fill:#ffffff;fill-opacity:1.0000000;stroke:#000000;stroke-width:0.46711226pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000" /> <text id="text1090" y="234.65482" x="367.81772" style="font-size:12.000000;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;font-family:Bitstream Vera Sans" xml:space="preserve"><tspan y="234.65482" x="367.81772" id="tspan1091" sodipodi:role="line">Quantification</tspan></text> <rect y="210.85860" x="643.53461" height="40.022114" width="79.088898" id="rect1096" style="fill:#ffffff;fill-opacity:1.0000000;stroke:#000000;stroke-width:0.41300855pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000" /> <text transform="translate(546.9541,32.49179)" id="text1097" y="202.8515" x="106.46902" style="font-size:12.000000;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;font-family:Bitstream Vera Sans" xml:space="preserve"><tspan y="202.85150" x="106.46902" id="tspan1098" sodipodi:role="line">Encodage</tspan></text> <rect y="387.36469" x="641.86285" height="38.918049" width="82.432426" id="rect1103" style="fill:#ffffff;fill-opacity:1.0000000;stroke:#000000;stroke-width:0.41579175pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000" /> <text transform="translate(545.2730,208.6861)" id="text1104" y="202.8515" x="106.46902" style="font-size:12.000000;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;font-family:Bitstream Vera Sans" xml:space="preserve"><tspan y="202.85150" x="106.46902" id="tspan1105" sodipodi:role="line">Décodage</tspan></text> <path sodipodi:nodetypes="cccc" id="path2746" d="M -127.28229,411.13437 L -138.52332,406.56174 L -138.52332,406.56174 L -127.28229,402.51307" style="fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:#000000;stroke-width:1.2500000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000" /> </g> <image y="166.86966" x="198.25000" id="image1272" height="128.00000" width="128.00000" sodipodi:absref="/home/sbrunner/Documents/Ondelet/img-all.png" xlink:href="img-all.png" /> <image y="166.86966" x="-107.70834" id="image1405" height="128.00000" width="128.00000" sodipodi:absref="/home/sbrunner/Documents/Ondelet/img-start.png" xlink:href="img-start.png" /> <image y="166.86966" x="491.31998" id="image1432" height="128.00000" width="128.00000" sodipodi:absref="/home/sbrunner/Documents/Ondelet/img-all.png" xlink:href="img-all.png" /> <image y="342.82373" x="491.31998" id="image1433" height="128.00000" width="128.00000" sodipodi:absref="/home/sbrunner/Documents/Ondelet/img-all.png" xlink:href="img-all.png" /> <image y="342.82370" x="-107.70834" id="image1434" height="128.00000" width="128.00000" sodipodi:absref="/home/sbrunner/Documents/Ondelet/img-start.png" xlink:href="img-start.png" /> </svg>
orthographe
[edit]il manque un "u" à Quantification, il me semble, quelque part... et le titre de l'image aurait pas un "t" en trop quelque part ? à schemaT ? --Moala 20 juillet 2005 à 11:21 (CEST)