title image


Smiley Re: Einzelne Punkte aus jpg-Bild auslesen?
Ich habe letztes Jahr eine Klasse geschrieben, die die wichtigsten Bildverarbeitungsfunktionen kapselt, Du solltest damit zurechtkommen, falls nicht, frag einfach. Das Einlesen eines JPGs wird von Java standardmäßig unterstützt, falls Du das im Netz oder sonst nicht findest, frag auch da noch :-)



// --------------------------------------------------------------------------------------

// JRasterImage

// --------------------------------------------------------------------------------------



import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.image.ImageObserver;

import java.awt.image.MemoryImageSource;

import java.awt.image.PixelGrabber;

import java.util.Arrays;



import javax.swing.JFrame;

import javax.swing.JProgressBar;



// --------------------------------------------------------------------------------------



public class JRasterImage

{

private Image m_Image;

private JHistogram m_Histogram;



// --------------------------------------------------------------------------------------

// Konstruktoren

// --------------------------------------------------------------------------------------



public JRasterImage()

{

m_Image = null;

m_Histogram = null;

}



// --------------------------------------------------------------------------------------



public JRasterImage(Image image)

{

m_Image = image;

}



// --------------------------------------------------------------------------------------

// Überschrieben

// --------------------------------------------------------------------------------------

/*

public Object clone()

{

JRasterImage copy = new JRasterImage((Image)m_Image.clone());

}

*/



// --------------------------------------------------------------------------------------

// Allgemeine Getter & Setter

// --------------------------------------------------------------------------------------



public Image getImage()

{

return m_Image;

}



// --------------------------------------------------------------------------------------



public void setImage(Image image)

{

m_Image = image;

}



// --------------------------------------------------------------------------------------



public Dimension getDimension(ImageObserver observer)

{

if (m_Image!=null)

{

return new Dimension(m_Image.getWidth(observer),

m_Image.getHeight(observer));

}

else

{

return new Dimension(0,0);

}

}



// --------------------------------------------------------------------------------------



public int getWidth(ImageObserver observer)

{

return m_Image != null ? m_Image.getWidth(observer) : 0;

}



// --------------------------------------------------------------------------------------



public int getHeight(ImageObserver observer)

{

return m_Image != null ? m_Image.getHeight(observer) : 0;

}



// --------------------------------------------------------------------------------------



public Graphics getGraphics()

{

return m_Image.getGraphics();

}



// --------------------------------------------------------------------------------------



public boolean isPanchromatic()

{

if (m_Histogram!=null)

{

return m_Histogram.isPanchromatic();

}



m_Histogram = getHistogram();



return m_Histogram.isPanchromatic();

}



// --------------------------------------------------------------------------------------



public void invalidateHistogram()

{

m_Histogram = null;

System.gc();

}



// --------------------------------------------------------------------------------------



public void setProgressBar(JProgressBar bar)

{

//m_ProgressBar = bar;

}



// --------------------------------------------------------------------------------------

// Hilfsfunktionen

// --------------------------------------------------------------------------------------



private PixelGrabber getPixelGrabber(int[] pixelArray)

{

PixelGrabber result;



int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



if (pixelArray==null)

{

pixelArray = new int[nWidth*nHeight];

}



result = new PixelGrabber(m_Image,0,0,nWidth,nHeight,

pixelArray,0,nWidth);

return result;

}



// --------------------------------------------------------------------------------------



static public int RGBtoInteger (int red, int green, int blue)

{

return (int)((255 << 24) | (red << 16) | (green << 8) | blue);

}



// --------------------------------------------------------------------------------------



static public Color IntegerToRGB(int nValue)

{

Color result = new Color((nValue >> 16) & 0xff,

(nValue >> 8) & 0xff,

(nValue) & 0xff);

return result;

}



// --------------------------------------------------------------------------------------



static public long faculty(long n)

{

assert(n>-1);



if (n<2)

{

return 1;

}



int result = 2;

for (int i=3; i<=n; i++)

{

result *= i;

}



return result;

}



// --------------------------------------------------------------------------------------



static public long binomialCoefficient(long n, long k)

{

return k==0 ? 1 : faculty(n)/(faculty(k)*faculty(n-k));

}



// --------------------------------------------------------------------------------------

// Elementare Rasterzugriffe

// --------------------------------------------------------------------------------------



public Color getPixel(int x, int y)

{

int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int[] pixels = new int[nWidth*nHeight];



PixelGrabber grabber = getPixelGrabber(pixels);



try

{

grabber.grabPixels();

}

catch (Exception e)

{

return null;

}



return IntegerToRGB(pixels[nWidth*y+x]);

}



// --------------------------------------------------------------------------------------



public int[] getPixels()

{

if (m_Image==null)

{

return null;

}

else

{

int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int[] pixels = new int[nWidth*nHeight];



PixelGrabber grabber = getPixelGrabber(pixels);



try

{

grabber.grabPixels();

}

catch (Exception e)

{

return null;

}



return pixels;

}

}



// --------------------------------------------------------------------------------------

// Bildverarbeitungs-Funktionen

// --------------------------------------------------------------------------------------



public JHistogram getHistogram()

{

if (m_Histogram==null)

{

m_Histogram = new JHistogram(this);

}



return m_Histogram;

}



// --------------------------------------------------------------------------------------



public void mirrorImage(boolean bHorizontal, boolean bVertical)

{

System.gc();



if ((!(bHorizontal||bVertical))||(m_Image==null))

{

return;

}



int[] nOldPixels = getPixels();

int n = nOldPixels.length;

int[] nNewPixels = new int[n];



int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



if (bHorizontal&&bVertical) // in beiden Richtungen spiegeln

{

for (int i=0; i
{

nNewPixels[i] = nOldPixels[n-i-1];

}

}

else

{

int x;

int y;



if (bHorizontal) // nur horizontal spiegeln

{

for (x=0; x
{

for (y=0; y
{

nNewPixels[nWidth*y+x] = nOldPixels[nWidth*y+(nWidth-1-x)];

}

}

}

else // nur vertikal spiegeln

{

for (x=0; x
{

for (y=0; y
{

nNewPixels[nWidth*y+x] = nOldPixels[nWidth*(nHeight-1-y)+x];

}

}

}

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void scaleImage(int nWidth, int nHeight, int nMode)

{

if (m_Image==null)

{

return;

}



assert((nMode==NEAREST_NEIGHBOR)||(nMode==BILINEAR_INTERPOLATION));

assert((nWidth>0)&&(nHeight>0));



int nOldWidth = m_Image.getWidth(null);

int nOldHeight = m_Image.getHeight(null);

double dXstep = ((double)nOldWidth)/(double)nWidth;

double dYstep = ((double)m_Image.getHeight(null))/(double)nHeight;



int nNewLength = nWidth*nHeight;



int[] nNewPixels = new int[nNewLength];

int[] nOldPixels = getPixels();



int x;

int y;



System.runFinalization();



switch (nMode)

{

case NEAREST_NEIGHBOR:

{

int nOldX;

int nOldY;



for (int i=0; i
{

x = i % nWidth;

y = i / nWidth;



nOldX = (int)Math.round(dXstep*(0.5+(double)x));

nOldY = (int)Math.round(dYstep*(0.5+(double)y));



if (nOldX==nOldWidth)

{

nOldX--;

}



if (nOldY==nOldHeight)

{

nOldY--;

}



nNewPixels[i] = nOldPixels[nOldWidth*nOldY+nOldX];

}

}

break;



case BILINEAR_INTERPOLATION:

{

double dLeft;

double dRight;

double dUpper;

double dLower;



int nLeft;

int nRight;

int nUpper;

int nLower;



int nX;

int nY;

Color color;



double dPixelArea = dXstep*dYstep;



double dRedSum;

double dGreenSum;

double dBlueSum;

double dCoverage;

double dCoverLeft;

double dCoverRight;

double dCoverUpper;

double dCoverLower;



for (y=0; y
{

for (x=0; x
{

// Koordinaten des entsprechenden Pixels im alten Bild berechnen

dLeft = x * dXstep;

dRight = dLeft + dXstep;

dUpper = y * dYstep;

dLower = dUpper + dYstep;

nLeft = (int)Math.floor(dLeft);

nUpper = (int)Math.floor(dUpper);



nRight = (int)Math.ceil(dRight);

if (nRight>=nOldWidth)

{

nRight = nOldWidth-1;

}



nLower = (int)Math.ceil(dLower);

if (nLower>=nOldHeight)

{

nLower = nOldHeight-1;

}



// Farbanteils-Summen auf null setzen

dRedSum = 0;

dBlueSum = 0;

dGreenSum = 0;





nY=nUpper;



do // über alle Zeilen

{

nX = nLeft;



do // über alle Spalten

{

// Begrenzungskoordinaten des Anteils berechnen

dCoverLeft = (dLeft>(double)nX) ? dLeft : (double)nX;

dCoverRight = (((double)nX+1)>dRight) ? dRight : (double)nX+1;

dCoverUpper = (dUpper>(double)nY) ? dUpper : (double)nY;

dCoverLower = (((double)nY+1)>dLower) ? dLower : (double)nY+1;



// Fläche des Anteils berechnen

dCoverage = (dCoverRight-dCoverLeft)*(dCoverLower-dCoverUpper);



// Farbe des Anteils holen

color = IntegerToRGB(nOldPixels[nOldWidth*nY+nX]);



dRedSum += (dCoverage/dPixelArea)*(double)color.getRed();

dGreenSum += (dCoverage/dPixelArea)*(double)color.getGreen();

dBlueSum += (dCoverage/dPixelArea)*(double)color.getBlue();



nX++;

}

while(nX


nY++;

}

while (nY


nNewPixels[y*nWidth+x] = RGBtoInteger((int)Math.round(dRedSum),

(int)Math.round(dGreenSum),

(int)Math.round(dBlueSum));

}

}

}

break;

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void applyMeanFilter(int nFilterWidth)

{

if (m_Image==null)

{

return;

}



assert((nFilterWidth%2!=0)&&(nFilterWidth>1));



int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int nOldPixels[] = getPixels();

int nNewPixels[] = new int[nWidth*nHeight];



int nHalfFilterWidth = (int)nFilterWidth/2;



int x;

int y;

int xm;

int ym;



double dDivisor;

int nLeft;

int nRight;

int nUpper;

int nLower;



int nRedSum;

int nGreenSum;

int nBlueSum;

Color color;



for (y=0; y
{

for (x=0; x
{

nRedSum = 0;

nGreenSum = 0;

nBlueSum = 0;



nLeft = (x-nHalfFilterWidth<0) ? 0 : x-nHalfFilterWidth;

nRight = (x+nHalfFilterWidth>=nWidth) ? (nWidth-1) : x+nHalfFilterWidth;

nUpper = (y-nHalfFilterWidth<0) ? 0 : y-nHalfFilterWidth;

nLower = (y+nHalfFilterWidth>=nHeight) ? (nHeight-1) : y+nHalfFilterWidth;



dDivisor = (double)((nRight-nLeft+1)*(nLower-nUpper+1));



for (xm=nLeft; xm<=nRight; xm++)

{

for (ym=nUpper; ym<=nLower; ym++)

{

color = IntegerToRGB(nOldPixels[nWidth*ym+xm]);



nRedSum += color.getRed();

nGreenSum += color.getGreen();

nBlueSum += color.getBlue();

}

}



nNewPixels[nWidth*y+x] = RGBtoInteger

((int)(((double)Math.round(nRedSum))/dDivisor),

(int)(((double)Math.round(nGreenSum))/dDivisor),

(int)(((double)Math.round(nBlueSum))/dDivisor));

}

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void applyMedianFilter(int nFilterWidth)

{

if (m_Image==null)

{

return;

}



assert((nFilterWidth%2!=0)&&(nFilterWidth>1));



int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int nHalfFilterWidth = (int)nFilterWidth/2;



int x;

int y;

int xm;

int ym;

int nMedianIndex;



int nLeft;

int nRight;

int nUpper;

int nLower;



int[] nRedVals = new int[nFilterWidth*nFilterWidth];

int[] nGreenVals = new int[nFilterWidth*nFilterWidth];

int[] nBlueVals = new int[nFilterWidth*nFilterWidth];



int nCurrentIndex;

int nStandardMatrixSize = (nFilterWidth*nFilterWidth)/2;

int nCurrentMatrixSize;



int nOldPixels[] = getPixels();

int nNewPixels[] = new int[nWidth*nHeight];



Color color;



System.runFinalization();



for (y=0; y
{

for (x=0; x
{

nLeft = (x-nHalfFilterWidth<0) ? 0 : x-nHalfFilterWidth;

nRight = (x+nHalfFilterWidth>=nWidth) ? (nWidth-1) : x+nHalfFilterWidth;

nUpper = (y-nHalfFilterWidth<0) ? 0 : y-nHalfFilterWidth;

nLower = (y+nHalfFilterWidth>=nHeight) ? (nHeight-1) : y+nHalfFilterWidth;



nCurrentMatrixSize = (nRight-nLeft+1)*(nLower-nUpper+1);

nMedianIndex = nCurrentMatrixSize/2;



nCurrentIndex = 0;



for (xm=nLeft; xm<=nRight; xm++)

{

for (ym=nUpper; ym<=nLower; ym++)

{

color = IntegerToRGB(nOldPixels[nWidth*ym+xm]);



nRedVals[nCurrentIndex] = color.getRed();

nGreenVals[nCurrentIndex] = color.getGreen();

nBlueVals[nCurrentIndex] = color.getBlue();



nCurrentIndex++;

}

}



if (nCurrentMatrixSize
{

for (xm=nCurrentMatrixSize; xm
{

nRedVals[xm] = 512;

nGreenVals[xm] = 512;

nBlueVals[xm] = 512;

}

}



Arrays.sort(nRedVals);

Arrays.sort(nGreenVals);

Arrays.sort(nBlueVals);



nNewPixels[nWidth*y+x] = RGBtoInteger(nRedVals[nMedianIndex],

nGreenVals[nMedianIndex],

nBlueVals[nMedianIndex]);

}

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nRedVals = null;

nGreenVals = null;

nBlueVals = null;

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void applyBinomialFilter(int nFilterWidth)

{

if (m_Image==null)

{

return;

}



assert((nFilterWidth%2!=0)&&(nFilterWidth>1));



int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int nOldPixels[] = getPixels();

int nNewPixels[] = new int[nWidth*nHeight];



int nHalfFilterWidth = (int)nFilterWidth/2;





// Berechnung der Koeffizienten-Matrix



int[][] nFilterMatrix = new int[nFilterWidth][nFilterWidth];



int x;



for (x=0; x
// Koeffizienten füllen

{

nFilterMatrix[0][x] = (int)binomialCoefficient(nFilterWidth-1,x);

nFilterMatrix[x][0] = nFilterMatrix[0][x];

}



int y;



for (x=1; x
// Produkten der Koeffizienten füllen

{

for (y=1; y
{

nFilterMatrix[x][y] = nFilterMatrix[0][y]*nFilterMatrix[x][0];

}

}



double dMainSum = 0; // Berechnung der Koeffizientensumme

for (x=0; x
{

for (y=0; y
{

dMainSum += nFilterMatrix[x][y];

}

}



double dRedSum;

double dGreenSum;

double dBlueSum;



Color color;



int nLeft;

int nRight;

int nUpper;

int nLower;



int xm;

int ym;



System.gc();



double dSum;



for (y=0; y
{

for (x=0; x
{

// Grenzen der ins Bild transformierten Filtermatrix berechen

// (notwendig, falls letztere nicht vollständig im Bild)

nLeft = (x-nHalfFilterWidth<0) ? 0 : x-nHalfFilterWidth;

nRight = (x+nHalfFilterWidth>=nWidth) ? (nWidth-1) : x+nHalfFilterWidth;

nUpper = (y-nHalfFilterWidth<0) ? 0 : y-nHalfFilterWidth;

nLower = (y+nHalfFilterWidth>=nHeight) ? (nHeight-1) : y+nHalfFilterWidth;



dSum = dMainSum; // die Koeffizientensumme muss immer wieder neu

// geholt werden, für den Fall, dass im vorherigen Durchlauf die Summe

// einer Teilmatrix verwendet wurde.



if ((nRight-nLeft+1
// Filtermatrix liegt nicht vollständig im Bild, Summe neu aus den

// Gewichten der innerhalb des Bildes liegenden Pixel berechnen

{

dSum = 0;



for (xm = nLeft; xm<=nRight; xm++)

{

for (ym = nUpper; ym<=nLower; ym++)

{

dSum += nFilterMatrix[xm-(x-nHalfFilterWidth)]

[ym-(y-nHalfFilterWidth)];

}

}

}



dRedSum = 0;

dGreenSum = 0;

dBlueSum = 0;



// Über alle unter der Filtermatrix liegenden Pixel laufen und

// die Farbanteile den entsprechenden Summen aufaddieren

for (xm=nLeft; xm<=nRight; xm++)

{

for (ym=nUpper; ym<=nLower; ym++)

{

color = IntegerToRGB(nOldPixels[nWidth*ym+xm]);



dRedSum += nFilterMatrix[xm-nLeft][ym-nUpper] * color.getRed();

dGreenSum += nFilterMatrix[xm-nLeft][ym-nUpper] * color.getGreen();

dBlueSum += nFilterMatrix[xm-nLeft][ym-nUpper] * color.getBlue();

}

}



// Neues Pixel aus Mittelwerten der Summen erzeugen

nNewPixels[nWidth*y+x] = RGBtoInteger((int)Math.round(dRedSum/dSum),

(int)Math.round(dGreenSum/dSum),

(int)Math.round(dBlueSum/dSum));

}

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nFilterMatrix = null;

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void applyUserDefinedFilter(double[][] nFilterMatrix, boolean bScaleValid)

{

if (m_Image==null)

{

return;

}



assert (nFilterMatrix!=null);



int nFilterWidth = nFilterMatrix[0].length;

int nFilterHeight = nFilterMatrix.length;



assert((nFilterWidth%2!=0)&&(nFilterHeight%2!=0));



int nHalfFilterWidth = nFilterWidth / 2;

int nHalfFilterHeight = nFilterHeight / 2;



int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int nOldPixels[] = getPixels();

int nNewPixels[] = new int[nWidth*nHeight];



int x;

int y;



double dMainSum = 0; // Berechnung der Koeffizientensumme

for (x=0; x
{

for (y=0; y
{

dMainSum += nFilterMatrix[y][x];

}

}





double j;



double dNegativeSum = 0;

double dPositiveSum = 0;

double dDistance = 0;



if (bScaleValid)

// Berechnung des möglichen Werteintervalls

{

for (x=0; x
{

for (y=0; y
{

j = nFilterMatrix[y][x];



if (j<0)

{

dNegativeSum += j;

}

else if (j>0)

{

dPositiveSum += j;

}

}

}



dNegativeSum *= 255.0;

dPositiveSum *= 255.0;

dDistance = dPositiveSum-dNegativeSum;

}



double dRedSum;

double dGreenSum;

double dBlueSum;



Color color;



int nLeft;

int nRight;

int nUpper;

int nLower;



int xm;

int ym;



System.runFinalization();



double dSum;



for (y=0; y
{

for (x=0; x
{

// Grenzen der ins Bild transformierten Filtermatrix berechen

// (notwendig, falls letztere nicht vollständig im Bild)

nLeft = (x-nHalfFilterWidth<0) ? 0 : x-nHalfFilterWidth;

nRight = (x+nHalfFilterWidth>=nWidth) ? (nWidth-1) : x+nHalfFilterWidth;

nUpper = (y-nHalfFilterHeight<0) ? 0 : y-nHalfFilterHeight;

nLower = (y+nHalfFilterHeight>=nHeight) ? (nHeight-1) : y+nHalfFilterHeight;



dSum = dMainSum; // die Koeffizientensumme muss immer wieder neu

// geholt werden, für den Fall, dass im vorherigen Durchlauf die Summe

// einer Teilmatrix verwendet wurde.



if ((nRight-nLeft+1
// Filtermatrix liegt nicht vollständig im Bild => Summe neu aus den

// Gewichten der innerhalb des Bildes liegenden Pixel berechnen

{

dSum = 0;



for (xm = nLeft; xm<=nRight; xm++)

{

for (ym = nUpper; ym<=nLower; ym++)

{

dSum += nFilterMatrix[ym-(y-nHalfFilterHeight)]

[xm-(x-nHalfFilterWidth)];

}

}

}



dRedSum = 0;

dGreenSum = 0;

dBlueSum = 0;



// Über alle unter der Filtermatrix liegenden Pixel laufen und

// die Farbanteile den entsprechenden Summen aufaddieren

for (xm=nLeft; xm<=nRight; xm++)

{

for (ym=nUpper; ym<=nLower; ym++)

{

color = IntegerToRGB(nOldPixels[nWidth*ym+xm]);



dRedSum += nFilterMatrix[ym-nUpper][xm-nLeft]

* (double)color.getRed();

dGreenSum += nFilterMatrix[ym-nUpper][xm-nLeft]

* (double)color.getGreen();

dBlueSum += nFilterMatrix[ym-nUpper][xm-nLeft]

* (double)color.getBlue();

}

}





if (bScaleValid)

{

nNewPixels[nWidth*y+x] =

RGBtoInteger((int)Math.round(255.0*dRedSum/dDistance),

(int)Math.round(255.0*dGreenSum/dDistance),

(int)Math.round(255.0*dBlueSum/dDistance));

}

else

{

nNewPixels[nWidth*y+x] =

RGBtoInteger((int)Math.round(dRedSum),

(int)Math.round(dGreenSum),

(int)Math.round(dBlueSum));

}

}

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nFilterMatrix = null;

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void applyLookupTable(int[] nRedLUT, int[] nGreenLUT, int[] nBlueLUT)

{

if (m_Image==null)

{

return;

}



assert((nRedLUT!=null)&&(nGreenLUT!=null)&&(nBlueLUT!=null));

assert((nRedLUT.length>255)&&(nGreenLUT.length>255)&&(nBlueLUT.length>255));



int[] nOldPixels = getPixels();

int n = nOldPixels.length;

int[] nNewPixels = new int[n];

int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int x;

int y;



Color color;



for (int i=0; i
{

x = i % nWidth;

y = i / nWidth;



color = IntegerToRGB(nOldPixels[nWidth*y+x]);

nNewPixels[nWidth*y+x] = RGBtoInteger(nRedLUT[color.getRed()],

nGreenLUT[color.getGreen()],

nBlueLUT[color.getBlue()]);

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void makePanchromatic()

{

if (m_Image==null)

{

return;

}



int[] nOldPixels = getPixels();

int n = nOldPixels.length;

int[] nNewPixels = new int[n];

int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int x;

int y;



int nMean;

Color color;



for (int i=0; i
{

x = i % nWidth;

y = i / nWidth;



color = IntegerToRGB(nOldPixels[nWidth*y+x]);

nMean = (int)Math.round(((double)(color.getRed()+color.getGreen()

+color.getBlue()))/3.0);



nNewPixels[nWidth*y+x] = RGBtoInteger(nMean, nMean, nMean);

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,

0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void swapColors()

{

if (m_Image==null)

{

return;

}



int[] nOldPixels = getPixels();

int n = nOldPixels.length;

int[] nNewPixels = new int[n];

int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int x;

int y;



int nRed;

int nGreen;

int nBlue;



Color color;



for (int i=0; i
{

x = i % nWidth;

y = i / nWidth;



color = IntegerToRGB(nOldPixels[nWidth*y+x]);



nRed = 255-color.getRed();

nGreen = 255-color.getGreen();

nBlue = 255-color.getBlue();



nNewPixels[nWidth*y+x] = RGBtoInteger(nRed, nGreen, nBlue);

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public void changeChannelIntensities(double dRedFactor,double dGreenFactor,

double dBlueFactor)

{

if (m_Image==null)

{

return;

}



assert(dRedFactor>=0);

assert(dGreenFactor>=0);

assert(dBlueFactor>=0);



int[] nOldPixels = getPixels();

int n = nOldPixels.length;

int[] nNewPixels = new int[n];

int nWidth = m_Image.getWidth(null);

int nHeight = m_Image.getHeight(null);



int x;

int y;



int nRed;

int nGreen;

int nBlue;



Color color;



for (int i=0; i
{

x = i % nWidth;

y = i / nWidth;



color = IntegerToRGB(nOldPixels[nWidth*y+x]);



nRed = (int)((dRedFactor*(double)color.getRed())%256.0);

nGreen = (int)((dGreenFactor*(double)color.getGreen())%256.0);

nBlue = (int)((dBlueFactor*(double)color.getBlue())%256.0);



nNewPixels[nWidth*y+x] = RGBtoInteger(nRed, nGreen, nBlue);

}



JFrame f = new JFrame();

m_Image = null;

m_Image = f.createImage(new MemoryImageSource(nWidth,nHeight,nNewPixels,0,nWidth));

nOldPixels = null;

nNewPixels = null;

m_Histogram = null;

System.runFinalization();

}



// --------------------------------------------------------------------------------------



public static final int



NEAREST_NEIGHBOR = 1,

BILINEAR_INTERPOLATION = 2;

}



// --------------------------------------------------------------------------------------


________________________________________________________________

Je mehr wir wissen, um so tiefer schweigen wir und um so hoffnungsloser vereinsamen wir.
José Ortega y Gasset
________________________________________________________________
Mikroseite / Heimseite


geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: