New Contributor

Joined:

Jul 6, 2018

## Need help with graphing a binary image matrix

Hello, I have an image which is a binary 2D matrix.
Is there a way I can graph it on JMP? The graph should show a black dot for ones and nothing for zeros.
Attached is the file that needs to be graphed.
Thaks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions

Super User

Joined:

Jun 22, 2012

Solution

## Re: Need help with graphing a binary image matrix

Here are a couple of ways to do this.  The first one is a cell plot.  To do this, one needs to correct your data table.

1. Delete row 1.

2. Select all columns

3. Using Standardize Attributes, change all columns from a Data Type of Character to a Data Type of Numeric.

4. Using Standardize Attributes, create a Column Property of Value Colors, and set the color of the value 0 to white, and the color of the value 1 to black

5. Run the Cell Plot Platform

Graph==>Cell Plot

Select all of the column and place them into the Y Response, and click on OK

The second example is to use the Graph Builder

1. Taking the above modified data table, a new column representing the row the data is in needs to be added. So, add a column called "Row" and set it's formula to

Row()

2. The data now needs to be stacked into basically one column of the zeros and ones.  Using the

Tables==>Stack

platform, copy all of the columns, "Column 2" thru "Column 26" into the Stack Columns.

3. In the "Non-stacked columns" section, select the "Select" checkbox, and the choose the "Row" column.

3. Click on OK

4. In the new stacked data table, create a new column called "Column" and set the formula to

Num(Word(-1,:Label," "))

This will take the column number from the Label column, and make it a numeric value in the new colum

5. Open the Graph Builder Platform

Graph==>Graph Builder

6. Drag the Row column to the Y drop area

7. Drag the Column column to the X drop area

8. Right click on the graph and select

Smoother==>Remove

9. Drag the Data column to the Color drop area

10. Right click on the colored dot for the 0 in the legend and select

Color==>White

11. Right click on the colored dot for the 1 in the segend and select

Color==>Black

You will get this chart

Other methods are available too.

Jim
3 REPLIES

Super User

Joined:

Jun 22, 2012

Solution

## Re: Need help with graphing a binary image matrix

Here are a couple of ways to do this.  The first one is a cell plot.  To do this, one needs to correct your data table.

1. Delete row 1.

2. Select all columns

3. Using Standardize Attributes, change all columns from a Data Type of Character to a Data Type of Numeric.

4. Using Standardize Attributes, create a Column Property of Value Colors, and set the color of the value 0 to white, and the color of the value 1 to black

5. Run the Cell Plot Platform

Graph==>Cell Plot

Select all of the column and place them into the Y Response, and click on OK

The second example is to use the Graph Builder

1. Taking the above modified data table, a new column representing the row the data is in needs to be added. So, add a column called "Row" and set it's formula to

Row()

2. The data now needs to be stacked into basically one column of the zeros and ones.  Using the

Tables==>Stack

platform, copy all of the columns, "Column 2" thru "Column 26" into the Stack Columns.

3. In the "Non-stacked columns" section, select the "Select" checkbox, and the choose the "Row" column.

3. Click on OK

4. In the new stacked data table, create a new column called "Column" and set the formula to

Num(Word(-1,:Label," "))

This will take the column number from the Label column, and make it a numeric value in the new colum

5. Open the Graph Builder Platform

Graph==>Graph Builder

6. Drag the Row column to the Y drop area

7. Drag the Column column to the X drop area

8. Right click on the graph and select

Smoother==>Remove

9. Drag the Data column to the Color drop area

10. Right click on the colored dot for the 0 in the legend and select

Color==>White

11. Right click on the colored dot for the 1 in the segend and select

Color==>Black

You will get this chart

Other methods are available too.

Jim

New Contributor

Joined:

Jul 6, 2018

## Re: Need help with graphing a binary image matrix

Thank you very much!
Highlighted

Community Trekker

Joined:

Sep 11, 2013

## Re: Need help with graphing a binary image matrix

Here is another way to do this, with JSL and creating an image file

``````// data preparation, the data table needs some work to get it ready
_dt = Current Data Table();
_dt << Select rows( 1 );
_dt << delete rows;

For( ii = 1, ii <= N Cols( _dt ), ii++,
Column( _dt, ii ) << Set Name( "phase_" || Char( ii - 1 ) );
Column( _dt, ii ) << Set Data Type( Numeric );
Column( _dt, ii ) << Set Modeling Type( Continuous );
);

// Make an image file and display in new window with scaling control

// this assumes the entire table just has the binary columns
// get the binary values as a matrix
m = _dt << get as matrix;

//  get the dimensions of the table/matrix
mdim = Dim( m );

// specify a minimum image size in pixels, this prevents the image from being
// too small to be useful
mininumimagepixeldim = [800 800];
// determine a scale factor to bring the size of the matrix up to the minimum dimensions
// specified above
scale_x = Ceiling( mininumimagepixeldim[2] / mdim[2] );
scale_y = Ceiling( mininumimagepixeldim[1] / mdim[1] );
// create a scaled image matrix, using the scale factors determined above
// and applying the direct product to scale up the image
r = 1 - Direct Product( m, J( scale_y, scale_x, 1 ) );

// create an image from the scaled image matrix
img = New Image( "rgb", {r, r, r} );
scalefactor = 1;

// create the display window
_nw = New Window( "Binary Image",
Outline Box( "Binary Image",
// create a slider controller to rescale the image
// this works by recreated the image, applying the scale factor,
// deleting the image in the display and redrawing the new image
V List Box(
H List Box(
Text Box( "Move Slider to Scale Image " ),
Slider Box(
.5,
1,
scalefactor,
img = New Image( "rgb", {r, r, r} );
img << Scale( scalefactor );
_picb << delete;
_panelb << Append( _picb = Picture Box( img ) )

;
)
),
// draw the binary image inside a panel box (just to give it an outline and a container)
_panelb = Panel Box( "Binary Image", _picb = Picture Box( img ) )
)
)
);``````

The result looks like this