Hallo Leute!
Ich habe ein Problem mit meinem Programm. Man hat ein 2D Array und muss den weißen Pixels reparieren. Ich muss alle Nachbarn finden, ihre Colors zu greifen und denn muss ich (averageRed/Green/Blue) machen. Wenn alles gut ist , muss ich den Pixel reparieren. Aber .. Ich habe alle Nachbarn gefunden , aber kann nicht ihre Color zu greifen. Können Sie mir helfen oder Idee geben?
[/I][/I][/I][/I][/I][/I]
Ich habe ein Problem mit meinem Programm. Man hat ein 2D Array und muss den weißen Pixels reparieren. Ich muss alle Nachbarn finden, ihre Colors zu greifen und denn muss ich (averageRed/Green/Blue) machen. Wenn alles gut ist , muss ich den Pixel reparieren. Aber .. Ich habe alle Nachbarn gefunden , aber kann nicht ihre Color zu greifen. Können Sie mir helfen oder Idee geben?
Java:
public class Picture {
private RGBColor imageMatrix[][];
private int width;
private int height;
public Picture(int width, int height){
this.height = height;
this.width = width;
createWhitePicture();
}
public Picture(String picUrl){
openAndSetPicture(picUrl);
}
public Picture(RGBColor imageMatrix[][]){
this.width = imageMatrix.length;
this.height = imageMatrix[0].length;
this.imageMatrix = imageMatrix;
}[I][I]
public void repairPicture(){
//TODO
int n=0;
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
if(imageMatrix[x][y].isWhite())
{
int leftx = x-1,
rightx = x+1,
upy = y-1,
downy = y+1;
if(x == 0)
{
leftx = x;
}
else if(x == width)
{
rightx = x;
}
if(y == 0)
{
upy = y;
}
else if(y == height)
{
downy = y;
}
int sumRed=0;
int sumBlue=0;
int sumGreen=0;
for(int i = leftx; i <= rightx; i++)
{
for(int j = upy; j <= downy; j++)
{
if ((imageMatrix[I][j].isWhite()==false)) {
sumRed= imageMatrix[I][j].getRed();
sumBlue =+ imageMatrix[I][j].getBlue();
sumGreen =+ imageMatrix[I][j].getGreen();
n++;
}
}
}
this.imageMatrix[x][y].setRGB(sumRed/n,sumBlue/n,sumGreen/n);
}
}
}
}
private boolean openAndSetPicture(String picUrl){
BufferedImage pic;
try {
InputStream iS= new FileInputStream(picUrl);
// get buffer of the picture
pic = ImageIO.read(iS);
// get additional picture informations
this.height = pic.getHeight();
this.width = pic.getWidth();
// store rgb colors in picture
this.imageMatrix = new RGBColor[this.width][this.height];
ColorModel cm= ColorModel.getRGBdefault();
for (int w=0; w< this.width; w++){
for(int h=0; h< this.height; h++){
// read out every RGBcolor
int pixel = pic.getRGB(w, h);
int rVal= cm.getRed(pixel);
int gVal= cm.getGreen(pixel);
int bVal= cm.getBlue(pixel);
//set this colors in picture
this.imageMatrix[w][h] = new RGBColor(rVal, gVal, bVal);
}
}
return true;
}catch (IOException e) {
e.printStackTrace();
}
return false;
}
public void createWhitePicture(){
this.imageMatrix = new RGBColor[this.width][this.height];
for (int w=0; w< this.width; w++){
for(int h=0; h< this.height; h++){
//set this colors in picture
this.imageMatrix[w][h] = new RGBColor(255, 255, 255);
}
}
}
public BufferedImage getImage(){
BufferedImage buf = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB);
for(int w=0; w<this.width; w++){
for(int h=0; h<this.height; h++){
int red= this.imageMatrix[w][h].getRed();
int blue= this.imageMatrix[w][h].getBlue();
int green= this.imageMatrix[w][h].getGreen();
int rgbVal= new Color(red, green, blue).getRGB();
buf.setRGB(w, h, rgbVal);
}
}
return buf;
}
}