【图像处理GUI】图像颜色过滤、颜色强调、反转颜色等(Matlab代码实现)

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

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

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

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

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

【图像处理GUI】提供多种图像处理功能

这个GUI设计用于展示一些基本的图像处理功能,并且能够满足用户对图像颜色过滤、颜色强调、反转颜色等需求。用户只需加载任何基本图像文件类型,即可利用提供的功能生成想要的图像效果。

该演示程序提供了一些非常基础的图像处理功能。下图显示了实现的GUI的截图。一般来说,图形用户界面(GUI)会绘制加载的原始图像,并提供一系列处理功能,用户可以选择任意功能来生成他们所需的图像效果。此外,在图形用户界面的左侧,还绘制了两幅图像的RGB直方图,帮助用户进一步了解图像的色彩分布情况。

通过这个GUI,用户可以轻松实现对图像的色彩控制和调整。颜色过滤功能允许用户选择特定的颜色通道进行过滤,以突出显示或减弱某种颜色。颜色强调功能则可以增强图像中的某个或多个颜色,使其更加鲜明和突出。反转颜色功能则能够将图像的颜色取反,带来截然不同的视觉效果。

此外,该GUI还支持其他一些图像处理功能,如运动过滤、锐化、模糊等。用户可以根据自己的需求选择使用这些功能,以达到更好的图像效果。

综上,这个图像处理GUI为用户提供了一个简单而强大的工具,让他们能够轻松实现对图像的颜色处理和效果增强。无论是普通用户还是专业设计师,都能够通过这个GUI实现他们对图像的个性化处理需求。

📚2 运行结果

图1:提供的图形用户界面的截图
具体而言,通过GUI按钮提供以下功能:
 加载文件:使用此按钮加载图像文件。在当前版本中,仅支持JPEG、GIF、TIFF和BMP图像格式。
保存文件:使用此按钮保存当前的辅助图像。
复制:此按钮将原始图像复制到辅助图像中。
灰度:此按钮生成原始(加载的)图像的灰度版本。
中值:此按钮在原始图像上应用中值滤波。为此,调用Matlab内置函数medfilt2。此外,用户需要提供滤波器掩模的大小,不是以像素为单位,而是以原始图像尺寸的百分比表示(例如,宽度的2%和高度的3%)。图2(b)展示了中值滤波的示例(滤波器大小选择为图像尺寸的3%)。

运动:此功能应用了一种近似相机线性运动的滤波器。为了生成适当的滤波器掩模,调用函数fspecial,并设置"motion"属性值。此时,用户需要提供运动方向(以度为单位,[0..360])以及运动长度(不是以像素为单位,而是以图像较大尺寸的百分比表示)。为了应用生成的掩模,使用imfilter函数。图2(c)和2(d)分别展示了0度和90度运动方向的运动滤波过程的结果。
锐化:此按钮对原始图像进行锐化。为了生成锐化掩模,使用了fspecial函数。此外,使用了imfilter函数来应用采用的图像滤波器。图2(e)给出了该过程的示例。
过滤颜色:此功能创建了一个具有彩色区域的原始图像的灰度版本。当按下相应的按钮时,用户需要为R、G和B系数中的每个系数提供3个阈值(范围为[0..255]),阈值越大,颜色阈值就越"宽松"(即,一般来说,较大的阈值会导致图像中有更多的彩色区域)。然后,用户将获得原始图像的副本,并被要求使用鼠标在图像上选择5个点。然后,计算这些颜色的平均值,并对图像应用简单的阈值处理步骤(使用在过程开始时提供的阈值)。在图2(f)中,我们从黄色(出租车上)选择了5个点,而R、G和B系数的颜色阈值分别选择为130、130和30。
颜色强调:此功能允许用户强调RGB空间的特定系数。在图2(g)中,我们通过150%强调了R系数。
反转颜色:此按钮用于反转图像的颜色。图2(h)给出了此功能的示例。
更改对比度和亮度:在设置对比度和亮度因子后(使用提供的滑块),使用此按钮。图2(i)显示了亮度和对比度调整的示例。

整体效果:

 部分代码:

% --- Outputs from this function are returned to the command line.
function varargout = imageProc_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in LoadButton.
function LoadButton_Callback(hObject, eventdata, handles)
% hObject    handle to LoadButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[FileName,PathName] = uigetfile({'*.*'},'Load Image File');

if (FileName==0) % cancel pressed
    return;
end


handles.fullPath = [PathName FileName];
[a, b, Ext] = fileparts(FileName);
availableExt = {'.bmp','.jpg','.jpeg','.tiff','.png','.gif'};
FOUND = 0;
for (i=1:length(availableExt))
    if (strcmpi(Ext, availableExt{i}))
        FOUND=1;
        break;
    end
end

if (FOUND==0)
    h = msgbox('File type not supported!','Error','error');
    return;
end

set(handles.sliderRotate, 'Enable', 'on');
set(handles.sliderBright, 'Enable', 'on');
set(handles.sliderContrast, 'Enable', 'on');
set(handles.editPath, 'Visible', 'on');
set(handles.editSize, 'Visible', 'on');
set(handles.editComment, 'Visible', 'on');


info = imfinfo(handles.fullPath);
if (~isempty(info.Comment))
    % save current image comment (to be used later in image save)
    handles.currentImageComment = info.Comment{1};
else
    handles.currentImageComment = '';
end

set(handles.editSize, 'String', sprintf('SIZE (W x H) : %d x %d', info.Width, info.Height));
set(handles.editComment, 'String', sprintf('COMMENT: %s', handles.currentImageComment));
set(handles.editPath', 'String', handles.fullPath);

% --- Outputs from this function are returned to the command line.
function varargout = imageProc_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in LoadButton.
function LoadButton_Callback(hObject, eventdata, handles)
% hObject    handle to LoadButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[FileName,PathName] = uigetfile({'*.*'},'Load Image File');

if (FileName==0) % cancel pressed
    return;
end


handles.fullPath = [PathName FileName];
[a, b, Ext] = fileparts(FileName);
availableExt = {'.bmp','.jpg','.jpeg','.tiff','.png','.gif'};
FOUND = 0;
for (i=1:length(availableExt))
    if (strcmpi(Ext, availableExt{i}))
        FOUND=1;
        break;
    end
end

if (FOUND==0)
    h = msgbox('File type not supported!','Error','error');
    return;
end

set(handles.sliderRotate, 'Enable', 'on');
set(handles.sliderBright, 'Enable', 'on');
set(handles.sliderContrast, 'Enable', 'on');
set(handles.editPath, 'Visible', 'on');
set(handles.editSize, 'Visible', 'on');
set(handles.editComment, 'Visible', 'on');


info = imfinfo(handles.fullPath);
if (~isempty(info.Comment))
    % save current image comment (to be used later in image save)
    handles.currentImageComment = info.Comment{1};
else
    handles.currentImageComment = '';
end

set(handles.editSize, 'String', sprintf('SIZE (W x H) : %d x %d', info.Width, info.Height));
set(handles.editComment, 'String', sprintf('COMMENT: %s', handles.currentImageComment));
set(handles.editPath', 'String', handles.fullPath);

 

🎉3 参考文献

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

[1]王凤兰,曙光,洪炳镕.彩色图像处理中照明颜色的过滤方法[J].哈尔滨工业大学学报, 2004, 36(007):949-950.DOI:10.3321/j.issn:0367-6234.2004.07.034.

[2]关丛荣,王虹.基于RGB空间的彩色图像处理GUI设计[J].黑龙江工程学院学报, 2008, 22(2):5.DOI:10.3969/j.issn.1671-4679.2008.02.020.

[3]关丛荣,王虹.基于RGB空间的彩色图像处理GUI设计[J].黑龙江工程学院学报(自然科学版), 2008.

[4]廖春生.浅谈图形图像处理中的几种颜色模式[J].佳木斯职业学院学报, 2011, 000(005):169-170.

🌈4 Matlab代码实现

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值