rust(50)-图像(3)
DynamicImage
DynamicImage是所有受支持的ImageBuffer
類型的枚舉。它的確切圖像類型是在運(yùn)行時(shí)確定的。它是打開圖像時(shí)返回的類型。為了方便,動(dòng)態(tài)圖像重新實(shí)現(xiàn)了所有的圖像處理功能。
DynamicImage實(shí)現(xiàn)RGBA像素的一般圖像特征。
SubImage
以矩形坐標(biāo)為界的另一幅圖像的視圖。它用于在圖像的子區(qū)域上執(zhí)行圖像處理功能。
這些是在imageops模塊中定義的函數(shù)。所有函數(shù)都對實(shí)現(xiàn)GenericImage trait.的類型進(jìn)行操作。
blur: 模糊:對提供的圖像執(zhí)行高斯模糊。
brighten: 變亮:變亮提供的圖像
huerotate:色調(diào)將提供的圖像按程度旋轉(zhuǎn)
contrast 對比度:調(diào)整提供的圖像的對比度
crop:裁剪:將一個(gè)可變的視圖返回到一個(gè)圖像中
filter3x3:對提供的圖像執(zhí)行一個(gè)3x3框式過濾器。
flip_horizontal: 水平翻轉(zhuǎn):水平翻轉(zhuǎn)圖像
flip_vertical:將圖像垂直翻轉(zhuǎn)
grayscale: 灰度:將提供的圖像轉(zhuǎn)換為灰度
invert: 反轉(zhuǎn):反轉(zhuǎn)提供的圖像中的每個(gè)像素。
resize:調(diào)整大小:將提供的圖像調(diào)整到指定的尺寸
rotate180:順時(shí)針旋轉(zhuǎn)圖像180度。
rotate旋轉(zhuǎn)270:順時(shí)針旋轉(zhuǎn)圖像270度。
rotate90:順時(shí)針旋轉(zhuǎn)圖像90度。
unsharpen: 未銳化:對提供的映像執(zhí)行未銳化掩碼
打開和保存圖像
image提供用于從路徑打開圖像的open函數(shù)。圖像格式由路徑的文件擴(kuò)展名決定。io模塊提供了一個(gè)提供更多控制的閱讀器。
生成的分形
//! 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(); }寫原始緩沖區(qū)
如果由于圖像是通過其他方式獲得的,因此不需要高級接口,則image提供save_buffer函數(shù)來將緩沖區(qū)保存到文件中。
總結(jié)
以上是生活随笔為你收集整理的rust(50)-图像(3)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu mysql master
- 下一篇: 包含内部类的.java文件编译后生成几个