【交互式阈值二进制图像】采用彩色或单色图像通过交互/手动方式阈值单色图像或彩色图像的单个色带研究(Matlab代码实现)

本文主要是介绍【交互式阈值二进制图像】采用彩色或单色图像通过交互/手动方式阈值单色图像或彩色图像的单个色带研究(Matlab代码实现),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

【交互式阈值二进制图像】采用彩色或单色图像通过交互/手动方式阈值单色图像或彩色图像的单个色带

本文介绍了一种交互式阈值二进制图像的方法。该方法可以应用于彩色或单色图像,并且允许用户通过滑块的方式以交互/手动的方式设置图像的阈值范围。

阈值图像是一种二进制图像,可以用作其他图像的遮罩图像。在阈值范围内的像素将在中间图像中显示为二进制图像(黑/白),而原始图像的像素将在左侧图像中显示为遮罩(灰度或彩色)。用户可以通过设置最大和最小阈值来调整阈值范围,从而实现对图像的二值化处理。

该方法的输入包括要开始的低阈值和高阈值,以及图像文件名或图像矩阵。可以处理的图像类型包括整数类型(如uint8、uint16等)和浮点类型(如单精度、双精度)。

该方法的输出包括阈值范围和用于选择阈值的最后一个色带。用户可以根据自己的需求选择合适的阈值范围,并通过调整滑块来实现图像的二值化处理。

通过使用交互式阈值二进制图像的方法,用户可以更加灵活地处理彩色或单色图像,并根据需要调整阈值范围,从而得到满足自己需求的二值化图像。该方法具有简单、直观的操作界面,适用于各种图像处理应用场景。

📚2 运行结果

部分代码:

% Read in a standard MATLAB gray scale demo image.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')% File doesn't exist.  Try it without the folder.% It might be able to find it in a folder off the search path.fullFileName = baseFileName;if ~exist(fullFileName, 'file')% Can't find it off the search path either.errorMessage = sprintf('Error: cannot find demo image %s', baseFileName);uiwait(msgbox(errorMessage));return;end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
axis off;
title('Original Grayscale Image', 'FontSize', fontSize);
% Set up figure properties.
set(gcf, 'Name', 'Thresholding Demo by ImageAnalyst', 'NumberTitle', 'off') 
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.message = sprintf('Thresholding demo by ImageAnalyst.\n\nDo you want to use an integer image or a floating point image?');
button = questdlg(message, 'Image Type?', 'Integer', 'Floating Point', 'Cancel', 'Integer');
drawnow;	% Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Cancel')close(gcf);	% Get rid of window.return;
end
if strcmpi(button, 'Floating Point')% Convert to double in the range -5000 to + 15000% Get input min and max.minGL = double(min(grayImage(:)));maxGL = double(max(grayImage(:)));% Scale the imageimageToThreshold = 20000 * mat2gray(grayImage) - 5000;% Verify themminDblGL = min(imageToThreshold(:));maxDblGL = max(imageToThreshold(:));fprintf('Before scaling, min gray level = %.1f, max gray level = %.1f\nAfter scaling,  min gray level = %.1f, max gray level = %.1f\n', ...minGL, maxGL, minDblGL, maxDblGL);startingLowThreshold = -800;startingHighThreshold = 10400;% Get the histogram[pixelCount, grayLevels] = hist(imageToThreshold(:), 300);subplot(2, 3, 2); bar(grayLevels, pixelCount, 'BarWidth', 1, 'FaceColor', 'b');title('Histogram of Original Double Image', 'FontSize', fontSize);xlim([minDblGL, maxDblGL]); % Scale x axis manually.

% Read in a standard MATLAB gray scale demo image.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
    % File doesn't exist.  Try it without the folder.
    % It might be able to find it in a folder off the search path.
    fullFileName = baseFileName;
    if ~exist(fullFileName, 'file')
        % Can't find it off the search path either.
        errorMessage = sprintf('Error: cannot find demo image %s', baseFileName);
        uiwait(msgbox(errorMessage));
        return;
    end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);

% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
axis off;
title('Original Grayscale Image', 'FontSize', fontSize);
% Set up figure properties.
set(gcf, 'Name', 'Thresholding Demo by ImageAnalyst', 'NumberTitle', 'off') 
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.

message = sprintf('Thresholding demo by ImageAnalyst.\n\nDo you want to use an integer image or a floating point image?');
button = questdlg(message, 'Image Type?', 'Integer', 'Floating Point', 'Cancel', 'Integer');
drawnow;    % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Cancel')
    close(gcf);    % Get rid of window.
    return;
end
if strcmpi(button, 'Floating Point')
    % Convert to double in the range -5000 to + 15000
    % Get input min and max.
    minGL = double(min(grayImage(:)));
    maxGL = double(max(grayImage(:)));
    % Scale the image
    imageToThreshold = 20000 * mat2gray(grayImage) - 5000;
    % Verify them
    minDblGL = min(imageToThreshold(:));
    maxDblGL = max(imageToThreshold(:));
    fprintf('Before scaling, min gray level = %.1f, max gray level = %.1f\nAfter scaling,  min gray level = %.1f, max gray level = %.1f\n', ...
        minGL, maxGL, minDblGL, maxDblGL);
    startingLowThreshold = -800;
    startingHighThreshold = 10400;
    % Get the histogram
    [pixelCount, grayLevels] = hist(imageToThreshold(:), 300);
    subplot(2, 3, 2); 
    bar(grayLevels, pixelCount, 'BarWidth', 1, 'FaceColor', 'b');
    title('Histogram of Original Double Image', 'FontSize', fontSize);
    xlim([minDblGL, maxDblGL]); % Scale x axis manually.

🎉3 参考文献

文章中一些内容引自网络,会注明出处或引用为参考文献,难免有未尽之处,如有不妥,请随时联系删除。

[1]龙建武,申铉京,陈海鹏.基于图像区域的交互式文本图像阈值分割算法[J].计算机研究与发展, 2012, 49(7):12.DOI:CNKI:SUN:JFYZ.0.2012-07-005.

[2]龙建武申铉京陈海鹏.基于图像区域的交互式文本图像阈值分割算法[J].计算机研究与发展, 2012, 49(7):1420-1431.

[3]兰红.多阈值优化的交互式医学图像分割方法[J].计算机科学, 2013, 40(9):4.DOI:10.3969/j.issn.1002-137X.2013.09.066.

🌈4 Matlab代码实现

这篇关于【交互式阈值二进制图像】采用彩色或单色图像通过交互/手动方式阈值单色图像或彩色图像的单个色带研究(Matlab代码实现)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/180778

相关文章

pandas中位数填充空值的实现示例

《pandas中位数填充空值的实现示例》中位数填充是一种简单而有效的方法,用于填充数据集中缺失的值,本文就来介绍一下pandas中位数填充空值的实现,具有一定的参考价值,感兴趣的可以了解一下... 目录什么是中位数填充?为什么选择中位数填充?示例数据结果分析完整代码总结在数据分析和机器学习过程中,处理缺失数

Golang HashMap实现原理解析

《GolangHashMap实现原理解析》HashMap是一种基于哈希表实现的键值对存储结构,它通过哈希函数将键映射到数组的索引位置,支持高效的插入、查找和删除操作,:本文主要介绍GolangH... 目录HashMap是一种基于哈希表实现的键值对存储结构,它通过哈希函数将键映射到数组的索引位置,支持

Pandas使用AdaBoost进行分类的实现

《Pandas使用AdaBoost进行分类的实现》Pandas和AdaBoost分类算法,可以高效地进行数据预处理和分类任务,本文主要介绍了Pandas使用AdaBoost进行分类的实现,具有一定的参... 目录什么是 AdaBoost?使用 AdaBoost 的步骤安装必要的库步骤一:数据准备步骤二:模型

使用Pandas进行均值填充的实现

《使用Pandas进行均值填充的实现》缺失数据(NaN值)是一个常见的问题,我们可以通过多种方法来处理缺失数据,其中一种常用的方法是均值填充,本文主要介绍了使用Pandas进行均值填充的实现,感兴趣的... 目录什么是均值填充?为什么选择均值填充?均值填充的步骤实际代码示例总结在数据分析和处理过程中,缺失数

Java对象转换的实现方式汇总

《Java对象转换的实现方式汇总》:本文主要介绍Java对象转换的多种实现方式,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java对象转换的多种实现方式1. 手动映射(Manual Mapping)2. Builder模式3. 工具类辅助映

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

利用Python调试串口的示例代码

《利用Python调试串口的示例代码》在嵌入式开发、物联网设备调试过程中,串口通信是最基础的调试手段本文将带你用Python+ttkbootstrap打造一款高颜值、多功能的串口调试助手,需要的可以了... 目录概述:为什么需要专业的串口调试工具项目架构设计1.1 技术栈选型1.2 关键类说明1.3 线程模

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

Python Transformers库(NLP处理库)案例代码讲解

《PythonTransformers库(NLP处理库)案例代码讲解》本文介绍transformers库的全面讲解,包含基础知识、高级用法、案例代码及学习路径,内容经过组织,适合不同阶段的学习者,对... 目录一、基础知识1. Transformers 库简介2. 安装与环境配置3. 快速上手示例二、核心模

Spring Boot读取配置文件的五种方式小结

《SpringBoot读取配置文件的五种方式小结》SpringBoot提供了灵活多样的方式来读取配置文件,这篇文章为大家介绍了5种常见的读取方式,文中的示例代码简洁易懂,大家可以根据自己的需要进... 目录1. 配置文件位置与加载顺序2. 读取配置文件的方式汇总方式一:使用 @Value 注解读取配置方式二