Problemas com PlanarImage do JAI

0 respostas
N

Estou com uma dificuldade em relação ao exemplo a seguir. Neste exemplo a entrade é um PlanarImage e a saída um TiledImage. Porém para o meu trabalho eu preciso realmente de uma saida PlanaImage. Procurei nas API’s mas não obtive sucesso. Gostaria que se fosse possível alguém me ajudasse neste problema. Tudo que contém neste trcho de código eu uso: obter um vetor a partir do PlanarImage, manipulá-lo e depois preciso convertê-lo novamente em um PlanaImage. Como posso fazer isto?

public static PlanarImage imagemFiltro(PlanarImage pi, String filtro, String passa, int corte, int ordem)   
    {   
        //recupera as dimensões da imagem   
        int width = pi.getWidth();   
        int height = pi.getHeight();   
           
        //recupera o numero de bandas da representacao (RGB-3, SCALE GRAY-1)   
        SampleModel sm = pi.getSampleModel();   
        int nbands = sm.getNumBands();   
System.out.println("nbands = "+nbands);           
        //recupera os dados de PlanarImage   
        Raster inputRaster = pi.getData();           
        double[] pixels = new double[nbands*width*height];   
        inputRaster.getPixels(0,0,width,height,pixels);   
           
        //passa a imagem de um vetor para uma matriz   
        double[][] mag = new double[width*nbands][height*nbands];   
        for(int h=0;h<height;h++)   
            for(int w=0;w<width;w++)   
            {   
                int offset = h*width*nbands+w*nbands;   
                for(int band=0;band<nbands;band++)   
                    mag[w*nbands][h*nbands] = pixels[offset+band];   
            }   
  
        //alica-se o filtro   
        if(filtro.equals("ideal"))   
        {   
               
        }               
        else if(filtro.equals("butterworth"))   
            mag = Butterworth(mag, corte, ordem, passa);   
        else if(filtro.equals("especial"))   
        {   
               
        }               
        else  
            throw new RuntimeException("ERRO: Nome de filtro invalido.");   
  
        for(int h=0;h<height;h++)   
            for(int w=0;w<width;w++)   
            {   
                int offset = h*width*nbands+w*nbands;   
                for(int band=0;band<nbands;band++)   
                    pixels[offset+band] = mag[w*nbands][h*nbands];   
            }   
  
           
        WritableRaster outputRaster = inputRaster.createCompatibleWritableRaster();   
        outputRaster.setPixels(0,0,width,height,pixels);   
        TiledImage ti = new TiledImage(pi,height,width);   
        ti.setData(outputRaster);   
           
        return pi;   
    }  
public static PlanarImage imagemFiltro(PlanarImage pi, String filtro, String passa, int corte, int ordem)
    {
        //recupera as dimensões da imagem
        int width = pi.getWidth();
        int height = pi.getHeight();
        
        //recupera o numero de bandas da representacao (RGB-3, SCALE GRAY-1)
        SampleModel sm = pi.getSampleModel();
        int nbands = sm.getNumBands();
System.out.println("nbands = "+nbands);        
        //recupera os dados de PlanarImage
        Raster inputRaster = pi.getData();        
        double[] pixels = new double[nbands*width*height];
        inputRaster.getPixels(0,0,width,height,pixels);
        
        //passa a imagem de um vetor para uma matriz
        double[][] mag = new double[width*nbands][height*nbands];
        for(int h=0;h<height;h++)
            for(int w=0;w<width;w++)
            {
                int offset = h*width*nbands+w*nbands;
                for(int band=0;band<nbands;band++)
                    mag[w*nbands][h*nbands] = pixels[offset+band];
            }

        //alica-se o filtro
        if(filtro.equals("ideal"))
        {
            
        }            
        else if(filtro.equals("butterworth"))
            mag = Butterworth(mag, corte, ordem, passa);
        else if(filtro.equals("especial"))
        {
            
        }            
        else
            throw new RuntimeException("ERRO: Nome de filtro invalido.");

        for(int h=0;h<height;h++)
            for(int w=0;w<width;w++)
            {
                int offset = h*width*nbands+w*nbands;
                for(int band=0;band<nbands;band++)
                    pixels[offset+band] = mag[w*nbands][h*nbands];
            }

        
        WritableRaster outputRaster = inputRaster.createCompatibleWritableRaster();
        outputRaster.setPixels(0,0,width,height,pixels);
        TiledImage ti = new TiledImage(pi,height,width);
        ti.setData(outputRaster);
        
        return pi;
    }
Criado 9 de maio de 2008
Respostas 0
Participantes 1