网站开发的形式是好用的微信公众号编辑器
- 作者: 五速梦信息网
- 时间: 2026年03月21日 07:38
当前位置: 首页 > news >正文
网站开发的形式是,好用的微信公众号编辑器,焦作市建设银行网站,百度怎么精准搜关键词对一个数字图像处理系统来说#xff0c;一般的处理过程为三个步骤#xff1a;图像预处理、特征抽取、图像识别和分析。图像的点运算就是预处理过程中的重要一步#xff0c;点运算是对图像的灰度级进行变换。 图像点运算概念 点运算是指对图像的每个像素依次进行相同的灰度变…对一个数字图像处理系统来说一般的处理过程为三个步骤图像预处理、特征抽取、图像识别和分析。图像的点运算就是预处理过程中的重要一步点运算是对图像的灰度级进行变换。 图像点运算概念 点运算是指对图像的每个像素依次进行相同的灰度变换然后得出的图像就是输出图像。那么对于RGB彩色图像的点运算是怎么处理的呢是有多种的处理方案的有简单对R、G、B分别操作的也有转换为灰度操作再还原为彩色的读者可以自行查阅资料。 点运算几个形式以及作用 对比度以及亮度调整 线性变换通过ykxd实现 对比度增强(k1) 拓展灰度分布范围突出细节差异例如医学影像中通过增大斜率是的病灶边缘更清晰亮度调节k1 d ! 0 整体平移灰度值用于低曝光图像全局提亮灰度反转k−1,d255用于突出暗区细节如X光片中的骨骼结构显示。 分段线性变换 对特定灰度区间进行选择性拉伸例如增强中间灰度区域的对比度保留极亮/极暗区域的信息 动态范围优化 非线性变换 对数变换压缩高灰度区域扩展低灰度细节适用于傅里叶频谱图等动态范围过宽的图像。伽马变换幂次变换 γ1扩展暗部细节适用于背光场景的修复。γ1增强亮部层次如卫星云图中云层纹理的区分 灰度直方图均衡化 像素、灰度、灰度级、灰度直方图 像素点是最小的图像单元一张图片由很多的像素点组成。比如之后我们用到的Kun图片就是939554像素的。 灰度是表明图像明暗的数值即黑白图像中点的颜色深度范围一般从0到255白色为255 黑色为0故黑白图片也称灰度图像。灰度值指的是单个像素点的亮度。灰度值越大表示越亮。 灰度就是没有色彩RGB色彩分量全部相等。图像的灰度化就是让像素点矩阵中的每一个像素点都满足关系RGB此时的这个值叫做灰度值。如RGB(100,100,100)就代表灰度值为100,RGB(50,50,50)代表灰度值为50 灰度值与像素值的关系:黑白图像的灰度值就是像素值彩色图像则需要进行一定的映射才可以得到灰度 灰度级不同灰度的种类个数 灰度直方图对灰度级进行统计 灰度直方图均衡化实操JAVA实例附源码 JavaSwing进行图片展示 先上网找一张我家哥哥的图片初始化一下Java项目然后就可以准备开始了。 利用JavaSwing进行图形化显示注意代码里边标注的他的图片读取默认目录是项目根目录 代码实现 import javax.imageio.ImageIO; import javax.swing.; import java.awt.; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.WritableRaster; import java.io.; public class Main {public static void main(String[] args) {SwingUtilities.invokeLater(() - {JFrame frame new JFrame(图片展示);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(800, 600);Image imagenull;try {//这里注意读取的默认位置是根目录InputStream is new BufferedInputStream(new FileInputStream(./asset/caixukun.png));Image originImage ImageIO.read(is);imageoriginImage;//imageoriginImage.getScaledInstance(400,300,Image.SCALE_SMOOTH);// BufferedImage bimageutils.toBufferedImage(image); // WritableRaster rasterbimage.getRaster(); // ColorModel colorModelbimage.getColorModel();//imageoriginImage;// 使用JLabel显示图片JLabel label new JLabel(new ImageIcon(image));frame.add(new JScrollPane(label));frame.pack();frame.setLocationRelativeTo(null);frame.setVisible(true);} catch (IOException e) {// 增强错误处理JOptionPane.showMessageDialog(frame,图片加载失败: e.getMessage(),错误,JOptionPane.ERROR_MESSAGE);System.exit(1);}});} } 观察图片效果良好这里读者可能会想把图像规范到一个固定的长宽比如400*300作者在这里尝试调用了Image的scale库最后的结果是bug预警后续调试观察RGB图像矩阵的时候像素值发生巨变通道数也变成了4总而言之就是不太看的明白的故障最终取消选择手工裁剪图片尺寸。 好这里打上断点查看一下图片格式 在raster(栅格)属性下的data栏目发现里边包括了RGB三个通道的所有点。 彩色图像映射成灰度图像 加权平均法由于人眼对不同颜色的敏感度不同对绿色的最高红色次之对蓝色最低所以通常的权重设置是R0.299, G0.587; B0.114;上课讲了U和V??? 简单平均法G(RGB)/3; 这里采用加权映射方法 代码实现 public static BufferedImage toGrayscaleImage(Image image) {// 先将 Image 转换为 BufferedImageBufferedImage bufferedImage toBufferedImage(image);int width bufferedImage.getWidth();int height bufferedImage.getHeight();for (int y 0; y height; y) {for (int x 0; x width; x) {Color color new Color(bufferedImage.getRGB(x, y));int grayLevel (int) (color.getRed() * 0.299 color.getGreen() * 0.587 color.getBlue() * 0.114);Color grayColor new Color(grayLevel, grayLevel, grayLevel);bufferedImage.setRGB(x, y, grayColor.getRGB());}}return bufferedImage;} 这里返回的bufferImage是image的子类可以在main函数里直接赋值给image看看转换之后的效果 灰度直方图绘制 utils里边增添Java代码 代码实现[Bug预警] public static BufferedImage drawGrayscaleHistogram(BufferedImage grayscaleImage) {int width grayscaleImage.getWidth();int height grayscaleImage.getHeight();// 统计每个灰度级的像素数量int[] histogram new int[256];for (int y 0; y height; y) {for (int x 0; x width; x) {Color color new Color(grayscaleImage.getRGB(x, y));int grayLevel color.getRed();histogram[grayLevel];}}// 找到直方图中的最大像素数量int maxCount 0;for (int count : histogram) {if (count maxCount) {maxCount count;}}int histogramWidth 512;int histogramHeight 400;BufferedImage histogramImage new BufferedImage(histogramWidth, histogramHeight, BufferedImage.TYPE_INT_RGB);Graphics2D g2d histogramImage.createGraphics();g2d.setColor(Color.WHITE);g2d.fillRect(0, 0, histogramWidth, histogramHeight);g2d.setColor(Color.BLACK);for (int i 0; i 256; i) {int barHeight (int) ((double) histogram[i] / maxCount * histogramHeight);g2d.drawLine(i, histogramHeight, i, histogramHeight - barHeight);}g2d.dispose();return histogramImage;} 直方图展示 其实这个图画的不是很好看点开数值看一下分布各个地方都有应该是纵轴尺度太大了。 对数概率代码实现没有意义只是证明一下各个像素其实都有 public static BufferedImage drawGrayscaleHistogram(BufferedImage grayscaleImage) {int width grayscaleImage.getWidth();int height grayscaleImage.getHeight();// 统计每个灰度级的像素数量int[] histogram new int[256];for (int y 0; y height; y) {for (int x 0; x width; x) {Color color new Color(grayscaleImage.getRGB(x, y));int grayLevel color.getRed();histogram[grayLevel];}}// 找到直方图中的最大像素数量int maxCount 0;for (int count : histogram) {if (count maxCount) {maxCount count;}}int histogramWidth 512;int histogramHeight 400;BufferedImage histogramImage new BufferedImage(histogramWidth, histogramHeight, BufferedImage.TYPE_INT_RGB);Graphics2D g2d histogramImage.createGraphics();g2d.setColor(Color.WHITE);g2d.fillRect(0, 0, histogramWidth, histogramHeight);g2d.setColor(Color.BLACK);double logMaxCount Math.log(maxCount 1);for (int i 0; i 256; i) {// 计算对数尺度下的柱子高度double logCount Math.log(histogram[i] 1);int barHeight (int) ((logCount / logMaxCount) * histogramHeight);g2d.drawLine(i * 2, histogramHeight, i * 2, histogramHeight - barHeight);}g2d.dispose();return histogramImage;} 注最后发现这么稀疏的原因是因为int除法向下取整全是0修改utils里边的这一小部分 for (int i 0; i 256; i) {//因该是这里的问题int barHeight (int)(((histogram[i] / (double)maxCount) * histogramHeight));g2d.drawLine(i * 2, histogramHeight, i * 2, histogramHeight - barHeight);} 经过调试还是因为这张图本身不是太好确实太集中了没能画出好图读者感兴趣可以换张图代码全都相同下边贴一张作者换图之后的直方图 换图之后的效果 灰度直方图分布含义 观察灰度直方图是为了对其进行操作在文章开始就有提到图像点运算是为了去做数据增强。 这里就得牵扯到一个对于灰度的理解。 整体灰度都偏向于一个区域的话大多数时候不是有利的会让画面看起来灰蒙蒙 较黑的图像 较亮的图像 灰度直方图均衡化 【直方图均衡化的核心思想亮度和对比度的改善】 并非灰度很高的图片或者灰度很低的图片看起来就会很清晰而是对比度高的图片看起来才会清晰特征分明这也就方便了各种识别任务。 过亮或者过暗的图片经过直方图均衡化会变得清晰。 直方图均衡化是一种简单有效的图像增强技术通过改变图像的直方图来改变图像中各像素的灰度主要用于增强动态范围偏小的图像的对比度。原始图像由于其灰度分布可能集中在较窄的区间造成图像不够清晰。例如过曝光图像的灰度级集中在高亮度范围内而曝光不足将使图像灰度级集中在低亮度范围内。采用直方图均衡化可以把原始图像的直方图变换为均匀分布均衡的形式这样就增加了像素之间灰度值差别的动态范围从而达到增强图像整体对比度的效果。换言之直方图均衡化的基本原理是对在图像中像素个数多的灰度值即对画面起主要作用的灰度值进行展宽而对像素个数少的灰度值即对画面不起主要作用的灰度值进行归并从而增大对比度使图像清晰达到增强的目的如下图所示。 如果一幅图像整体偏暗或者偏亮那么直方图均衡化的方法很适用。但直方图均衡化是一种全局处理方式它对处理的数据不加选择可能会增加背景干扰信息的对比度并且降低有用信号的对比度如果图像某些区域对比度很好而另一些区域对比度不好那采用直方图均衡化就不一定适用。此外均衡化后图像的灰度级减少某些细节将会消失某些图像如直方图有高峰经过均衡化后对比度不自然的过分增强。针对直方图均衡化的缺点已经有局部的直方图均衡化方法出现。 灰度直方图均衡化适用范围 直方图均衡化在需要增强局部细节的任务中表现优异比如识别任务但其对全局亮度分布的破坏性处理可能影响依赖整体光照语义的应用如图生文 贴几组均衡化的例子 左边是均衡化之前右边是之后 发现问题 上边的一系列例子里我们发现最后一张黑猫图片是个例外试图发现共性找出第二张可能有这种情况的例子这样的情况是由于黑白图片吗,是由于过暗的地方有光影吗现在是什么情况呢可能原图的色调太单一就那么几个所以均衡化之后 似乎黑白图片效果也很好和另一张有光影的图片也很好 灰度直方图均衡化思考 灰度直方图呈现的是一种图像整体的状态因为灰度级统计的是全部的图片所以造成上述结果的应该是一种“局部的特征”。我要不要找一找他的灰度分布情况呢 回答实时证明均衡化对于噪声的鲁棒性很差有噪声的时候就会导致颗粒感很足出来的画面会很奇怪。可以检测一下图片里的噪声 不难看出不是所有的灰度图像经过均衡化都会变得更加清晰的那么灰度直方图均衡化到底在哪些图上可能效果比较好呢我们看看他的操作方案 灰度直方图均衡化公式解释 如果把映射的分子分母上的-cdfMin去掉那是不是立马就能看懂了就是一个拉伸一个简单的解释是为了让映射范围有0所以这个公式的映射范围就变成了0~255之间。 最后的最后为了方便进行对比展示搭建了一个UI界面代码如下 import javax.imageio.ImageIO; import javax.swing.; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.; import java.awt.event.ActionEvent; import java.awt.image.BufferedImage; import java.io.*; import java.util.Arrays; public class ImageProcessorGUI extends JFrame {private BufferedImage originalImage;private BufferedImage processedImage;private JLabel imageLabel;private JComboBoxString operationComboBox;private JButton fileSelectButton;private final String[] OPERATIONS {原始图像, 灰度转换, 灰度直方图,均衡化后图片, 均衡化后直方图, 噪声点统计};public ImageProcessorGUI() {super(图像处理器);initializeUI();loadDefaultImage();}private void initializeUI() {setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(1000, 800);setLayout(new BorderLayout());// 控制面板JPanel controlPanel new JPanel();fileSelectButton new JButton(选择图片);operationComboBox new JComboBox(OPERATIONS);JButton processButton new JButton(执行);JButton refreshButton new JButton(重置);controlPanel.add(fileSelectButton);controlPanel.add(new JLabel(选择操作:));controlPanel.add(operationComboBox);controlPanel.add(processButton);controlPanel.add(refreshButton);// 图像显示区域imageLabel new JLabel() {Overridepublic Dimension getPreferredSize() {return getIcon() null ? new Dimension(0, 0) : super.getPreferredSize();}};imageLabel.setHorizontalAlignment(SwingConstants.CENTER);imageLabel.setVerticalAlignment(SwingConstants.CENTER);JScrollPane scrollPane new JScrollPane(imageLabel);add(controlPanel, BorderLayout.NORTH);add(scrollPane, BorderLayout.CENTER);// 事件监听fileSelectButton.addActionListener(e - selectImageFile());processButton.addActionListener(e - processImage());refreshButton.addActionListener(e - showOriginalImage());}private void loadDefaultImage() {loadImage(./asset/tanzhilang.png);}private void selectImageFile() {JFileChooser fileChooser new JFileChooser();fileChooser.setCurrentDirectory(new File(./asset));fileChooser.setFileFilter(new FileNameExtensionFilter(图像文件, jpg, jpeg, png, gif));if (fileChooser.showOpenDialog(this) JFileChooser.APPROVE_OPTION) {loadImage(fileChooser.getSelectedFile().getAbsolutePath());}}private void loadImage(String path) {try (InputStream is new BufferedInputStream(new FileInputStream(path))) {originalImage ImageIO.read(is);showOriginalImage();} catch (IOException ex) {JOptionPane.showMessageDialog(this, 图片加载失败: ex.getMessage(), 错误, JOptionPane.ERROR_MESSAGE);}}private void showOriginalImage() {processedImage originalImage;updateImageDisplay();}private void processImage() {int selectedIndex operationComboBox.getSelectedIndex();try {switch (selectedIndex){case 1:processedImage ImageUtils.toGrayscale(originalImage);break;case 2:processedImageutils.drawGrayscaleHistogram(ImageUtils.toGrayscale(originalImage));break;case 3:processedImage utils.histogramEqualization(ImageUtils.toGrayscale(originalImage));break;case 4:processedImage utils.histogramEqualization(ImageUtils.toGrayscale(originalImage));processedImageutils.drawGrayscaleHistogram(processedImage);break;case 5:int noisePoints utils.countNoisePoints(ImageUtils.toGrayscale(originalImage), 30);JOptionPane.showMessageDialog(this, 噪声点数量: noisePoints);return;default:processedImage originalImage;}updateImageDisplay();} catch (Exception ex) {JOptionPane.showMessageDialog(this, 处理失败: ex.getMessage(), 错误, JOptionPane.ERROR_MESSAGE);}}private void updateImageDisplay() {if (processedImage null) return;Dimension viewSize ((JScrollPane) getContentPane().getComponent(1)).getViewport().getExtentSize();int maxWidth Math.max(viewSize.width - 50, 100);int maxHeight Math.max(viewSize.height - 50, 100);Image scaledImage processedImage.getScaledInstance(Math.min(processedImage.getWidth(), maxWidth),Math.min(processedImage.getHeight(), maxHeight),Image.SCALE_SMOOTH);imageLabel.setIcon(new ImageIcon(scaledImage));imageLabel.revalidate();imageLabel.repaint();}public static void main(String[] args) {SwingUtilities.invokeLater(() - {ImageProcessorGUI app new ImageProcessorGUI();app.setLocationRelativeTo(null);app.setVisible(true);});} }class ImageUtils {// 灰度转换public static BufferedImage toGrayscale(BufferedImage image) {BufferedImage result new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);for (int y 0; y image.getHeight(); y) {for (int x 0; x image.getWidth(); x) {Color color new Color(image.getRGB(x, y));int gray (int) (color.getRed() * 0.299 color.getGreen() * 0.587 color.getBlue() * 0.114);result.setRGB(x, y, new Color(gray, gray, gray).getRGB());}}return result;}} 图形化界面展示 代码链接Keith1276/Gray-level-Histogram-Equalization-and-Linear-Transformation–in-Image-Processing-https://github.com/Keith1276/Gray-level-Histogram-Equalization-and-Linear-Transformation–in-Image-Processing-
- 上一篇: 网站开发的薪资是多少东莞搜狗推广
- 下一篇: 网站开发的形式是网站建设入什么会计科目
相关文章
-
网站开发的薪资是多少东莞搜狗推广
网站开发的薪资是多少东莞搜狗推广
- 技术栈
- 2026年03月21日
-
网站开发的项目总结高端定制建站公司
网站开发的项目总结高端定制建站公司
- 技术栈
- 2026年03月21日
-
网站开发的相关技能有哪些网站常用配色
网站开发的相关技能有哪些网站常用配色
- 技术栈
- 2026年03月21日
-
网站开发的形式是网站建设入什么会计科目
网站开发的形式是网站建设入什么会计科目
- 技术栈
- 2026年03月21日
-
网站开发的形式是无锡优化网站业务
网站开发的形式是无锡优化网站业务
- 技术栈
- 2026年03月21日
-
网站开发的研究背景网站设计带装修网站大概收费
网站开发的研究背景网站设计带装修网站大概收费
- 技术栈
- 2026年03月21日
