7d66a132创建于 2022年9月17日历史提交

Image Show

Examples

  1. Showing a gray-scale image.

::

let image = imread("./tests/imgs/imshow/lena_gray.tiff")
imshow(image)

Result:

.. image:: ../../../tests/imgs/imshow/imshow_1.png :align: center :width: 360

  1. Showing a color image.

::

let image = imread("./tests/imgs/imshow/lena_color.tiff")
imshow(image)

Result:

.. image:: ../../../tests/imgs/imshow/imshow_2.png :align: center :width: 360

  1. This example illustrates simple computing on image data: converting a gray-scale image to a black-and-white image.

::

let image = imread("./tests/imgs/imshow/lena_gray.tiff")
let gray = image[0].asMatrix()
let h = gray.getRows()
let w = gray.getCols()
var mean_density: Float64 = 0.0
for (i in 0..h) {
    for (j in 0..w) {
        mean_density += Float64(gray[i,j])
    }
}
mean_density /= Float64(h * w)
for (i in 0..h) {
    for (j in 0..w) {
        if (Float64(gray[i,j]) > mean_density) {
            gray[i,j] = 255
        } else {
            gray[i,j] = 0
        }
    }
}
imshow(gray)

Result:

.. image:: ../../../tests/imgs/imshow/imshow_3.png :align: center :width: 360

  1. imshow can be used directly on a file name.

::

imshow("./tests/imgs/imshow/lena_color.tiff")

Result: same as Example 1.

  1. This example demonstrates the use of palettes. The gray-scale image is shown using green colors.

::

let image = imread("./tests/imgs/imshow/lena_gray.tiff")
imshow(image[0].asMatrix())
colormap(Palette.Greens)

Result:

.. image:: ../../../tests/imgs/imshow/imshow_5.png :align: center :width: 360

  1. This example shows the same image using another palette: the default color map.

::

let image = imread("./tests/imgs/imshow/lena_gray.tiff")
imshow(image[0].asMatrix())
colormap(Palette.DefaultMap)

Result:

.. image:: ../../../tests/imgs/imshow/imshow_6.png :align: center :width: 360

  1. This example illustrates the vignette transformation on images.

::

let image = imread("./tests/imgs/imshow/lena_color.tiff")
let image2 = imvignette(image)
imshow(image2)

.. image:: ../../../tests/imgs/imshow/imshow_7.png :align: center :width: 360

  1. The effect of vignette on the gray-scale image.

::

let image = imread("./tests/imgs/imshow/lena_gray.tiff")
let image2 = imvignette(image)
imshow(image2)

.. image:: ../../../tests/imgs/imshow/imshow_8.png :align: center :width: 360

  1. This example shows the effect of resizing an image. The interpolation method used is bilinear.

::

let image = imread("./tests/imgs/imshow/lena_color.tiff")
let image2 = imresize(image, 0.1, interpolation: ImageInterpolation.Bilinear)
imshow(image2)

.. image:: ../../../tests/imgs/imshow/imshow_9.png :align: center :width: 360

  1. This example shows the effect of resizing the vignette of an image. The interpolation method is the default one (bicubic).

::

let image = imread("./tests/imgs/imshow/lena_color.tiff")
let image2 = imvignette(image)
let image3 = imresize(image2, 0.5)
imshow(image3)

.. image:: ../../../tests/imgs/imshow/imshow_10.png :align: center :width: 360

  1. This example shows another palette using blue colors.

::

let image = imread("./tests/imgs/imshow/lena_gray.tiff")
imshow(image[0].asMatrix())
colormap(Palette.Blues)

.. image:: ../../../tests/imgs/imshow/imshow_11.png :align: center :width: 360