|
| 1 | +# --- |
| 2 | +# title: Image Difference View |
| 3 | +# cover: assets/image_diffview.png |
| 4 | +# --- |
| 5 | + |
| 6 | +# This demonstration shows some common tricks in image comparision -- difference view |
| 7 | + |
| 8 | +# People with MATLAB experiences would miss the function |
| 9 | +# [`imshowpair`](https://www.mathworks.com/help/images/ref/imshowpair.html), but in JuliaImages |
| 10 | +# it is not that indispensable. |
| 11 | + |
| 12 | +using Images, MosaicViews |
| 13 | +using TestImages |
| 14 | + |
| 15 | +img = float.(testimage("cameraman")) |
| 16 | +## rotate img by 4 degrees and keep axes unchanged |
| 17 | +img_r = imrotate(img, -pi/45, axes(img)) |
| 18 | +nothing #hide #md |
| 19 | + |
| 20 | +# `mosaicview` is a convenience tool to show multiple images, especially useful when they have |
| 21 | +# different sizes and colors. |
| 22 | + |
| 23 | +mosaicview(img, img_r; nrow=1, npad=20, fillvalue=colorant"white") |
| 24 | + |
| 25 | +# In some cases, when the differences of two images are relative insignificant, a plain |
| 26 | +# substraction can help amplify the difference. |
| 27 | +plain_diffview = @. img - img_r |
| 28 | +nothing #hide #md |
| 29 | + |
| 30 | +# For gray images, a fancy trick is to fill each image into different RGB channels |
| 31 | +# and make a RGB view |
| 32 | +RGB_diffview = colorview(RGB, channelview(img), channelview(img_r), fill(0., size(img))) |
| 33 | +nothing #hide #md |
| 34 | + |
| 35 | +# or convert the RGB view back to Gray image after that |
| 36 | +Gray_diffview = Gray.(RGB_diffview) |
| 37 | + |
| 38 | +mosaicview(plain_diffview, RGB_diffview, Gray_diffview; |
| 39 | + nrow=1, npad=20, fillvalue=colorant"white") |
| 40 | + |
| 41 | + |
| 42 | +# --- save covers --- #src |
| 43 | +using FileIO #src |
| 44 | +save("assets/image_diffview.png", RGB_diffview) #src |
0 commit comments