cell values of a matrix from a pgm file

51 views
Skip to first unread message

Seong

unread,
Feb 10, 2014, 8:07:38 AM2/10/14
to gama-p...@googlegroups.com
Hi all,

I am trying to load a matrix from a pgm file. When I get a value from a specific cell [i, j] after loading the matrix, the value looks wrong.
So, I think there is a problem to get a proper value of each cell in the matrix.

To check each cell value of the matrix, I tried to write a pgm file from the matrix.
If I can get proper cell value from the matrix, new pgm file that I write has to be same with the original pgm file.

The results showed that two pgm files are different, and I don't know why.

Please give me some comments to figure this out.

Here is my code to read a pgm file as a matrix, and write a pgm file from the matrix.

//read

    string grid_filename <- "../includes/data/lc2009_200.pgm";
    const grid_matrix type: matrix of: int <- matrix (image ( grid_filename ));


//write

                string sfile <- "../includes/data/" + "lupgm05.pgm";
                save ('P2') to:  sfile type: "text" ;
                save ('2308 3034') to:  sfile type: "text" ;
                save ('999') to:  sfile type: "text" ;
               
                loop j from: 0 to: nrows -1  {
                    string str <- '';
                    loop i from : 0 to: ncols-1 {
                        if (i > 0) {
                            str <- str + " ";
                        }
                        str <- str +  grid_matrix[i, j];
                    }
                    save (str) to:  sfile type: "text" ;
                }           






Screen Shot 2014-02-10 at 21.53.27.png

Seong

unread,
Feb 12, 2014, 4:45:46 AM2/12/14
to
I also had a go with sugarscape.pgm, which is from the sugarscape toy model.
It seems that there is no problem if a pgm is square. However, if it is not a square type, there is a problem.
Am I right? Since my pgm is not a square type, how can I solve this problem?

Thanks for your time in advance.

Seong

sugarscape.pgm
sugarscape1.pgm

Patrick Taillandier

unread,
Feb 11, 2014, 6:13:10 AM2/11/14
to gama-p...@googlegroups.com
Hi,

For the second problem, you are right, there is a bug concerning the loading of non square pgm file.
I just commited the fix. If your are using the GAMA SVN version, you just have to update GAMA and it should work.

if your are using a release version of GAMA 1.6, a trick consists in changing the extension of your pgm file to csv one, then to load the file in a matrix:
const types type: file <- file('../images/sugarscape1.csv');
matrix mat_types <- matrix(types);
...
init { create animal number: numberOfAgents; ask sugar_cell { maxSugar <- int(mat_types at {grid_x,grid_y+3}); //+3 for the three first lines sugar <- maxSugar; color <- [white,FFFFAA,FFFF55,yellow,dark_yellow] at sugar; } }

Cheers,

Patrick


2014-02-11 6:23 GMT+01:00 Seong <seongk...@gmail.com>:
I also had a go with sugarscape.pgm, which is from the sugarscape toy model.
It seems that there is no problem if a pgm is square. However, if it is not a square, there is problem.
Am I right? Since my pgm is not a square, how can I solve this problem?


Thanks for your time in advance.

Seong

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages