rust(50)-图像(3)
DynamicImage
DynamicImage是所有受支持的ImageBuffer
類型的枚舉。它的確切圖像類型是在運行時確定的。它是打開圖像時返回的類型。為了方便,動態圖像重新實現了所有的圖像處理功能。
DynamicImage實現RGBA像素的一般圖像特征。
SubImage
以矩形坐標為界的另一幅圖像的視圖。它用于在圖像的子區域上執行圖像處理功能。
這些是在imageops模塊中定義的函數。所有函數都對實現GenericImage trait.的類型進行操作。
blur: 模糊:對提供的圖像執行高斯模糊。
brighten: 變亮:變亮提供的圖像
huerotate:色調將提供的圖像按程度旋轉
contrast 對比度:調整提供的圖像的對比度
crop:裁剪:將一個可變的視圖返回到一個圖像中
filter3x3:對提供的圖像執行一個3x3框式過濾器。
flip_horizontal: 水平翻轉:水平翻轉圖像
flip_vertical:將圖像垂直翻轉
grayscale: 灰度:將提供的圖像轉換為灰度
invert: 反轉:反轉提供的圖像中的每個像素。
resize:調整大小:將提供的圖像調整到指定的尺寸
rotate180:順時針旋轉圖像180度。
rotate旋轉270:順時針旋轉圖像270度。
rotate90:順時針旋轉圖像90度。
unsharpen: 未銳化:對提供的映像執行未銳化掩碼
打開和保存圖像
image提供用于從路徑打開圖像的open函數。圖像格式由路徑的文件擴展名決定。io模塊提供了一個提供更多控制的閱讀器。
生成的分形
//! An example of generating julia fractals. extern crate image; extern crate num_complex;fn main() {let imgx = 800;let imgy = 800;let scalex = 3.0 / imgx as f32;let scaley = 3.0 / imgy as f32;// Create a new ImgBuf with width: imgx and height: imgylet mut imgbuf = image::ImageBuffer::new(imgx, imgy);// Iterate over the coordinates and pixels of the imagefor (x, y, pixel) in imgbuf.enumerate_pixels_mut() {let r = (0.3 * x as f32) as u8;let b = (0.3 * y as f32) as u8;*pixel = image::Rgb([r, 0, b]);}// A redundant loop to demonstrate reading image datafor x in 0..imgx {for y in 0..imgy {let cx = y as f32 * scalex - 1.5;let cy = x as f32 * scaley - 1.5;let c = num_complex::Complex::new(-0.4, 0.6);let mut z = num_complex::Complex::new(cx, cy);let mut i = 0;while i < 255 && z.norm() <= 2.0 {z = z * z + c;i += 1;}let pixel = imgbuf.get_pixel_mut(x, y);let image::Rgb(data) = *pixel;*pixel = image::Rgb([data[0], i as u8, data[2]]);}}// Save the image as “fractal.png”, the format is deduced from the pathimgbuf.save("fractal.png").unwrap(); }寫原始緩沖區
如果由于圖像是通過其他方式獲得的,因此不需要高級接口,則image提供save_buffer函數來將緩沖區保存到文件中。
總結
以上是生活随笔為你收集整理的rust(50)-图像(3)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu mysql master
- 下一篇: centos mysql_CentOS