IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques en Java Discussion :

Afficher PlanarImage créer d'un array


Sujet :

Interfaces Graphiques en Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Août 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations forums :
    Inscription : Août 2007
    Messages : 86
    Par défaut Afficher PlanarImage créer d'un array
    salut

    j'applique un code pour faire une segmentation sur un PlanarImage, la classe fonctionne correctement, j'arrive a obtenir le nombre de région mais au moment d'afficher l'image résultante j'obtiens une page blanche, j'ai lu et relu le code et j'arrive pas a trouver où est le problème, le voici peut être qqn vera qqc que j'ai pas vu.

    le problème est au niveau de la méthode getOutput() qui me rend l'image.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
     
     private PlanarImage input,output;
      private int width,height;
      // A matrix for the pixel values, one for the selected labels, one which indicates
      // whether a pixel already has a label.
      private byte[][] pixels;
      private int[][] labels;
      // The position, i.e. number of estimated algorithm steps we've already done.
      private long position;
      // The number of regions on the (finished) task.
      private int numberOfRegions;
      // Counters for pixels in each region
      private Map<Integer,Integer> count;
    public Segmentation(PlanarImage im)
        {
     
        input = im;
        Raster inputRaster = input.getData();
        // Create the data structures needed for the algorithm.
        width = input.getWidth();
        height = input.getHeight();
        labels = new int[width][height];
        pixels = new byte[width][height];
        // Fill the data structures.
        for(int h=0;h<height;h++)
          for(int w=0;w<width;w++)
            {
            pixels[w][h] = (byte)inputRaster.getSample(w,h,0);
            labels[w][h] = -1;
            }
        position = 0;
        count = new TreeMap<Integer, Integer>();
        }
     
     
     /**
      * This method performs the bulk of the processing. It runs a classic stack-based
      * region growing algorithm:
      * 1 - Find a pixel which is not labeled. Label it and store its coordinates on a 
      *     stack.
      * 2 - While there are pixels on the stack, do:
      *   3 - Get a pixel from the stack (the pixel being considered).
      *   4 - Check its neighboors to see if they are unlabeled and close to the 
      *       considered pixel; if are, label them and store them on the stack.
      * 5 - Repeat from 1) until there are no more pixels on the image.      
      */
      public void run()
        {
        numberOfRegions = 0;
        Stack<Point> mustDo = new Stack<Point>();
        for(int h=0;h<height;h++)
          for(int w=0;w<width;w++)
            {
            position++;
            // Is this pixel unlabeled?
            if (labels[w][h] < 0)
              {
              numberOfRegions++;
              mustDo.add(new Point(w,h));
              labels[w][h] = numberOfRegions; // label it as one on a new region
              count.put(numberOfRegions,1);
              }
            // Check all the pixels on the stack. There may be more than one!
            while(mustDo.size() > 0)
              {
              Point thisPoint = mustDo.get(0); mustDo.remove(0);
              // Check 8-neighborhood
              for(int th=-1;th<=1;th++)
                for(int tw=-1;tw<=1;tw++)
                  {
                  int rx = thisPoint.x+tw;
                  int ry = thisPoint.y+th;
                  // Skip pixels outside of the image.
                  if ((rx < 0) || (ry < 0) || (ry>=height) || (rx>=width)) continue;
                  if (labels[rx][ry] < 0) 
                    if (pixels[rx][ry] == pixels[thisPoint.x][thisPoint.y])
                      { 
                      mustDo.add(new Point(rx,ry));
                      labels[rx][ry] = numberOfRegions;
                      count.put(numberOfRegions, count.get(numberOfRegions)+1);
                      }
                  } // ended neighbors checking
              } // ended stack scan 
            } // ended image scan
        position = width*height;
        }
     
     /**
      * This method returns the number of regions on the segmetation task. This
      * number may be partial if the task has not finished yet.
      */
      public int getNumberOfRegions()
        {
        return numberOfRegions;
        }
     
     /**
      * This method returns the pixel count for a particular region or -1 if the
      * region index is outside of the range.
      */ 
      public int getPixelCount(int region)
        {
        Integer c = count.get(region);
        if (c == null) return -1; else return c;
        }
     
     /**
      * This method returns the estimated size (steps) for this task. We estimate it as 
      * being the size of the image.
      */
      public long getSize()
        {
        return width*height;
        }
     
     /**
      * This method returns the position on the image processing task.
      */
      public long getPosition()
        {
        return position;
        }
     
     /**
      * This method returns true if the image processing task has finished.
      */
      public boolean isFinished()
        {
        return (position == width*height);
        }
     
     /**
      * This method returns the output image. It may be sort of corrupted if the image
      * processing task is still running.
      */
      public PlanarImage getOutput()
        {
        // Create a new image based on the labels array.
        int[] imageDataSingleArray = new int[width*height];
        int count=0;
        for(int h=0;h<height;h++)
          for(int w=0;w<width;w++)
            imageDataSingleArray[count++] = labels[w][h]; 
        // Create a Data Buffer from the values on the single image array.
        DataBufferInt dbuffer = new DataBufferInt(imageDataSingleArray,
                                                  width*height);
        // Create a byte data sample model.
        SampleModel sampleModel =
           RasterFactory.createBandedSampleModel(DataBuffer.TYPE_INT,width,height,1);
        // Create a compatible ColorModel.
        ColorModel colorModel = PlanarImage.createColorModel(sampleModel);
        // Create a WritableRaster.
        Raster raster = RasterFactory.createWritableRaster(sampleModel,dbuffer,new Point(0,0));
        // Create a TiledImage using the SampleModel and ColorModel.
        TiledImage tiledImage = new TiledImage(0,0,width,height,0,0,sampleModel,colorModel);
        // Set the data of the tiled image to be the raster.
        tiledImage.setData(raster);      
        return tiledImage;
        }
    }
    pour afficher l'image je fait ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Segmentation task = new Segmentation(img);				
    task.start();
    dj.set(task.getOutput()); // dj c'est le DisplayJAI
    merci pour l'aide

  2. #2
    Membre confirmé
    Inscrit en
    Août 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations forums :
    Inscription : Août 2007
    Messages : 86
    Par défaut
    j'ai trouvé, il fallait ajouter ce bout de code pour pouvoir afficher l'image:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    PlanarImage result = tiledImage;
          ParameterBlock pbConvert = new ParameterBlock();
           pbConvert.addSource(result);
          pbConvert.add(DataBuffer.TYPE_BYTE);
          result = JAI.create("format", pbConvert);

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Créer une propriété array
    Par JLC83 dans le forum Général VBA
    Réponses: 1
    Dernier message: 24/09/2009, 20h07
  2. Afficher le contenu d'un ARRAY dans DATAGRID
    Par luilui dans le forum Flex
    Réponses: 3
    Dernier message: 19/05/2009, 00h55
  3. [2.2.1] Afficher un tableau de valeurs (ARRAY)
    Par birt1976 dans le forum BIRT
    Réponses: 0
    Dernier message: 29/07/2008, 09h44
  4. [Tableaux] Afficher les clé d'un array
    Par Fusio dans le forum Langage
    Réponses: 2
    Dernier message: 12/06/2007, 17h12
  5. [Tableaux] Afficher id d'un tableau array
    Par Pepito2030 dans le forum Langage
    Réponses: 7
    Dernier message: 01/06/2007, 20h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo