使用移动平均的图像阈值处理
来源:互联网 发布:网店淘宝拍拍 编辑:程序博客网 时间:2024/06/09 23:21
使用移动平均的图像阈值处理
1、代码
clc;clear all;close all;f = imread('c.tif');figure;imshow(f);title('原图像');T = graythresh(f);g1 = im2bw(f, T); g2 = movingthresh(f, 20, 0.5);figure, imshow(g2);title('变换后');
函数movingthresh定义为:
function g = movingthresh(f, n, K)%MOVINGTHRESH Image segmentation using a moving average threshold.% G = MOVINGTHRESH(F, n, K) segments image F by thresholding its% intensities based on the moving average of the intensities along% individual rows of the image. The average at pixel k is formed% by averaging the intensities of that pixel and its n − 1% preceding neighbors. To reduce shading bias, the scanning is% done in a zig-zag manner, treating the pixels as if they were a% 1-D, continuous stream. If the value of the image at a point% exceeds K percent of the value of the running average at that% point, a 1 is output in that location in G. Otherwise a 0 is% output. At the end of the procedure, G is thus the thresholded% (segmented) image. K must be a scalar in the range [0, 1].% Preliminaries.f = tofloat(f);[M, N] = size(f);if (n < 1) || (rem(n, 1) ~= 0)error('n must be an integer >= 1.')endif K < 0 || K > 1error('K must be a fraction in the range [0, 1].')end% Flip every other row of f to produce the equivalent of a zig-zag% scanning pattern. Convert image to a vector.f(2:2:end, :) = fliplr(f(2:2:end, :));f = f'; % Still a matrix.f = f(:)'; % Convert to row vector for use in function filter.% Compute the moving average.maf = ones(1, n)/n; % The 1-D moving average filter.ma = filter(maf, 1, f); % Computation of moving average.% Perform thresholding.g = f > K * ma;% Go back to image format (indexed subscripts).g = reshape(g, N, M)';% Flip alternate rows back.g(2:2:end, :) = fliplr(g(2:2:end, :));
2、结果
0 1
- 使用移动平均的图像阈值处理
- 灰度图像--图像分割 阈值处理之平均阈值
- 灰度图像--图像分割 阈值处理之谷底阈值、峰顶平均
- 图像的阈值处理(Python)
- 图像分割--使用迭代算法的全局阈值处理
- 图像分割--使用Otsu方法的全局阈值处理
- 基于移动平均的图像分割
- Python下opencv使用笔记(四)(图像的阈值处理)
- 有关opencv的学习(13)—使用固定阈值处理图像
- 有关opencv的学习(14)—使用自适应阈值处理图像
- 图像分割—基于图像数据的自动选择阈值(基本全局阈值处理方法)
- python中使用mahotas包函数实现图像阈值处理
- Delphi图像处理 -- 设置阈值
- [matlab图像处理] 阈值分割
- Matlab 图像分割 (阈值处理)
- 图像处理------基于阈值模糊
- 图像处理19:简单阈值
- 图像处理20:自适应阈值
- Netty的由来之阻塞I/O模型BIO
- 树莓派3b安装新系统的步骤和一些问题(萌新看过来)
- 微信发送位置源码
- sql查询之左连接,右连接,内连接以及全外连接的使用(测试常见面试题欧)
- 第一篇技术博客
- 使用移动平均的图像阈值处理
- 我行我素购物管理系统(面向对象)
- 人工智能-机器学习之梯度学习
- Docker学习文档之二 搭建环境-Windows环境
- Python及Python第三方包安装
- c++11 获取毫秒数
- redis笔记-常用命令篇(采用与《redis入门指南》)
- 以太网帧格式(TCP/IP详解)
- Docker学习文档之二 搭建环境-Linux环境