数字图像处理——用Java对图像做镜像变换

来源:互联网 发布:数据侠客行txt网盘 编辑:程序博客网 时间:2024/06/07 06:19

水平镜像变换,也就是把图像的像素点按照垂直中线做调换。

代码实现也很简单:

import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;public class ImageMirror {    public static void main(String[] args) throws IOException{        File file = null;        BufferedImage image = null;        try {            file = new File("E:\\in.jpg");            image = ImageIO.read(file);            int width = image.getWidth();            int height = image.getHeight();            for (int j = 0; j < height; j++) {                int l = 0, r = width - 1;                while (l < r) {                    int pl = image.getRGB(l, j);                    int pr = image.getRGB(r, j);                    image.setRGB(l, j, pr);                    image.setRGB(r, j, pl);                    l++;                    r--;                }            }            file = new File("E:\\out.jpg");            ImageIO.write(image, "jpg", file);        } catch (IOException e) {            e.printStackTrace();        }    }}

输入:


这里写图片描述

输出:


这里写图片描述

阅读全文
0 0
原创粉丝点击