Does anyone know an easy way to visualise 2D arrays ? Any software that reads them in and displays them ?
Plot Data Visualiation for 2D arrays
Collapse
X
-
Tags: None
-
Originally posted by Ganon11Do you mean a way to display all the information in a 2D array in a good way, or a way for you personally to see what a 2D array is?Comment
-
The standard way to display 2D arrays is with a set of nested for...loops - an example is
Code:for (int r = 0; r < ROW_SIZE; r++) { for (int c = 0; c < COL_SIZE; c++) { cout << array[r][c] << " "; } cout << endl; }
Is this what you meant?Comment
-
I can see how you can print out the values in an array that way. What I need is more a software that allows to display them easily. Imagin your array is an image (e.g. a photo) that has values for different colors or intesitys that you want to have a look at. There must be something that reads an array in and displays it as an image...? Does that make sense ?Comment
-
I wrote some open source code to visualize 2D arrays. Have a look at the EasyBMP project, and take a look at the DataPlotter program.
IIRC, I need to update that program, so let me know if you encounter problems. But a pre-compiled version is included.
Also, here's a very simple way to visualize a 2D array in grayscale:
Code:#include "EasyBMP.h" // ... // suppose you already have an array data[i][j] // of size M x N // find the min and max of the array double min = 9e9; double max = -9e9; for( int i=0 ; i < M ;i++ ) { for( int j=0; j <N ; j++ ) { if( data[i][j] < min ) { min = data[i][j]; } if( data[i][j] > max ) { max = data[i][j]; } } } BMP Output; Output.SetSize(M,N); // plot the pixels for( int i=0 ; i < M ; i++ ) { for( int j=0; j < N ; j++ ) { double scaled_value = ( data[i][j] - min )/( max-min + 1e-16 ); ebmpBYTE pixel_value = (ebmpBYTE) ( scaled_value * 255.0 ); Output(i,j)->Red = pixel_value; Output(i,j)->Green = pixel_value; Output(i,j)->Blue = pixel_value; } } // save the file Output.WriteToFile( "image.bmp" );
I hope this helps! -- PaulComment
-
Do'h!
Still wasn't fast enough. Darn those stringent limits! :) Here it is for real. ;) -- PaulAttached FilesComment
-
Originally posted by macklin01Do'h!
Still wasn't fast enough. Darn those stringent limits! :) Here it is for real. ;) -- PaulComment
-
Originally posted by dschulenburgPaul, thanks, I'll have a quick look at your webpage ! Does that only work for C++ or also in C ?
While most of the code uses C, EasyBMP is implemented as a few C++ classes, particularly the BMP class. (The object-oriented nature of C++ makes it much easier to implement the read/write functions, etc.) Thanks -- PaulComment
Comment