In this example we want to compare two mechanical drawings (raster images) to see the differences.
In [1]:
NB. Load required scripts
load 'graphics/bmp viewmat'
In [2]:
NB. Read first bitmap image
i1 =: readbmp jpath '~user/Jupyter_Notebook_J_Example_Data/assembly1.bmp'
In [3]:
NB. Show first bitmap image
viewrgb i1
In [4]:
NB. Read second bitmap image
i2 =: readbmp jpath '~user/Jupyter_Notebook_J_Example_Data/assembly2.bmp'
In [5]:
NB. Show second bitmap image
viewrgb i2
In [6]:
NB. Utility verb to create an integer representation from an RGB triple
RGB =: 3 : 0
r =. |:0{|:y
g =. |:1{|:y
b =. |:2{|:y
i =. <.((r*2^16)+(g*2^8)+b)
)
In [7]:
NB. First compare the arrays i1,i2 then multiply the result with i1
ia =: i1 * i1 = i2
In [8]:
NB. Show the resulting bitmap image
viewrgb ia
In [9]:
NB. We extract the differences and color them in red
ib =: (RGB 255,0,0) * ia e. 0
In [10]:
viewrgb ib
In [11]:
NB. Join both images using OR
id =: ia +. ib
In [12]:
NB. Show image differences in red
viewrgb id
In [ ]: