IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 图像分割演示系统 -> 正文阅读

[人工智能]图像分割演示系统

function varargout = ImageSegmentation(varargin)
% IMAGESEGMENTATION MATLAB code for ImageSegmentation.fig
%      IMAGESEGMENTATION, by itself, creates a new IMAGESEGMENTATION or raises the existing
%      singleton*.
%
%      H = IMAGESEGMENTATION returns the handle to a new IMAGESEGMENTATION or the handle to
%      the existing singleton*.
%
%      IMAGESEGMENTATION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMAGESEGMENTATION.M with the given input arguments.
%
%      IMAGESEGMENTATION('Property','Value',...) creates a new IMAGESEGMENTATION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ImageSegmentation_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ImageSegmentation_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ImageSegmentation

% Last Modified by GUIDE v2.5 20-Apr-2016 13:59:55

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @ImageSegmentation_OpeningFcn, ...
    'gui_OutputFcn',  @ImageSegmentation_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

function InitAxes(handles)
% 清理
clc;
% 坐标系设置
axes(handles.axes1); cla reset;
set(handles.axes1, 'XTick', [], 'YTick', [], ...
    'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], 'Box', 'On');
% 坐标系设置
axes(handles.axes2); cla reset;
set(handles.axes2, 'XTick', [], 'YTick', [], ...
    'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], 'Box', 'On');

function filePath = OpenFile(imgfilePath)
% 打开文件
% 输出参数:
% filePath——文件路径

if nargin < 1
    % 设置默认参数
    imgfilePath = fullfile(pwd, 'images/lena.bmp');
end
% 选择文件对话框
[filename, pathname, filterindex] = uigetfile( ...
    { '*.bmp','All bmp Files';...
    '*.jpg','All jpg Files';...
    '*.*',  '所有文件 (*.*)'}, ...
    '选择文件', ...
    'MultiSelect', 'off', ...
    imgfilePath);
% 初始化
filePath = 0;
if isequal(filename, 0) || isequal(pathname, 0)
    % 如果选择无效
    return;
end
% 整合路径
filePath = fullfile(pathname, filename);


% --- Executes just before ImageSegmentation is made visible.
function ImageSegmentation_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to ImageSegmentation (see VARARGIN)

% Choose default command line output for ImageSegmentation
handles.output = hObject;
% 初始化
InitAxes(handles);
handles.I_origin = 0;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ImageSegmentation wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ImageSegmentation_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 选择文件
filePath = OpenFile();
if isequal(filePath, 0)
    % 如果选择文件无效
    return;
end
% 读取
I_origin = imread(filePath);
% 显示
axes(handles.axes1);
imshow(I_origin, []);
title('原图像');
% 存储
handles.I_origin = I_origin;
guidata(hObject, handles);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
    % 逐层处理
    I2(:,:,i) = edge(I1(:,:,i),'roberts');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Robert边缘检测');

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
    % 逐层处理
    I2(:,:,i) = edge(I1(:,:,i),'sobel');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Sobel边缘检测');

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
    % 逐层处理
    I2(:,:,i) = edge(I1(:,:,i),'prewitt');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Prewitt边缘检测');

% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
    % 逐层处理
    I2(:,:,i) = edge(I1(:,:,i),'log');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('LoG边缘检测');

% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
    % 逐层处理
    I2(:,:,i) = edge(I1(:,:,i),'canny');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Canny边缘检测');

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I1 = I_origin(:,:,ik);
    % 直方图统计
    [count, x] = imhist(I1);
    % 对直方图平滑,平滑1次
    z = medfilt1(count, 10);
    % 对直方图平滑,平滑2次
    z = medfilt1(z, 10);
    % 对直方图插值
    xi = 0:0.1:length(x)-1;
    % 样条插值
    yi = spline(x,z,xi);
    % 显示
    axes(handles.axes1);
    stem(x,count);
    title('直方图');
    hold on;
    plot(xi,yi,'r','LineWidth',3);
    hold off;
    % 初始化
    peakfound = 0;
    j = 1;
    K = [];
    for i = 201 : length(xi) - 201
        if yi(i)>yi(i-200) && yi(i)>yi(i+200) && yi(i)==max(yi(i-200:i+200))
            % 条件更新
            peakfound = 1;
            K(j) = i;
            j = j+1;
        end
    end
    % 长度
    n = length(K);
    % 初始化
    flag=0;
    if n == 2
        % 最小位置
        [~, t1] = min(yi(K(1):K(2)));
        KK = t1+K(1);
    elseif n > 2
        for i = 1:n-1
            % 最小位置
            [~, t] = min(yi(K(i):K(i+1)));
            KK(i) = t+K(i);
        end
    else
        % 更新标记
        flag = 1;
    end
    % 计算阈值,输出阈值已经归一化;
    if flag == 0
        % 阈值
        K_T = KK/length(xi);
        % 二值化
        I2 = im2bw(I1, K_T(1));
        % 显示
        axes(handles.axes2);
        imshow(I2, []);
        % 存储
        I_out(:,:,ik) = I2;
        title('极小值点阈值');
    elseif flag == 1
        disp('不是双峰或者多峰图');
    end
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('极小值点阈值');
end

% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
% 显示
axes(handles.axes1);
imshow(I_origin, []);
title('原图像');
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I = I_origin(:,:,ik);
    % 求出图象大小
    [R,C]=size(I);
    % 将图像矩阵浮点化以便运算
    I = double(I);
    % 求出最大的图象强度
    maxI = max(max(I));
    % 求出最小的图象强
    minI = min(min(I));
    % 浮点化以便运算
    maxI = double(maxI);
    minI = double(minI);
    % 将初始阈值设置为最大与最小图像强度的均值
    th = (maxI(1,1)+minI(1,1))/2;
    % 辅助阈值初始化
    th2 = 0;
    % 初始化大于阈值的元素的个数及其灰度总值
    p = 0.0;
    q = 0.0;
    % 初始化小于阈值的元素的个数及其灰度总值
    p2 = 0.0;
    q2 = 0.0;
    % 迭代式最佳阈值选择算法主体
    while abs(th2-th) > 0
        % 循环条件
        th2 = th;
        for i=1:R
            for j=1:C
                if I(i,j)>=th2
                    % 记录大于阈值的元素个数及其灰度总值
                    p=p+I(i,j);
                    q=q+1;
                end
                if I(i,j)
                    % 记录小于阈值的元素个数及其灰度总值
                    p2=p2+I(i,j);
                    q2=q2+1;
                end
            end
        end
        % 生成新阈值
        T0=p/q;
        T1=p2/q2;
        th=(T0+T1)/2;
        % 重置初值
        p=0.0;
        q=0.0;
        p2=0.0;
        q2=0.0;
    end
    % 计算阈值
    K_T = th/255;
    % 二值化
    I2 = im2bw(handles.I_origin, K_T);
    % 显示
    axes(handles.axes2);
    imshow(I2, []);
    title('最优阈值');
    I_out(:,:,ik) = I2;
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('最优阈值');
end

% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I = I_origin(:,:,ik);
    % 计算直方图
    [count, x]=imhist(I);
    % 显示
    axes(handles.axes1);
    stem(x,count);
    title('直方图');
    % 初始化阈值
    p = max(max(I));
    q = min(min(I));
    th = (p+q)/2;
    flag = 1;
    sz = size(I);
    while(flag)
        % 循环更新
        fg = 0;
        gb = 0;
        fs = 0;
        bs = 0;
        for i = 1:sz(1)
            for j = 1:sz(2)
                tmp = I(i,j);
                if tmp >= th
                    % 达到阈值
                    fg = fg + 1;
                    fs = fs + double(tmp);
                else
                    % 迭代
                    gb = gb+1;
                    bs = bs + double(tmp);
                end
            end
        end
        % 计算中间结果
        t0 = fs/fg;
        t1 = bs/gb;
        tk = uint8(t0+t1)/2;
        if tk == th
            % 达到平衡
            flag = 0;
        else
            % 继续
            th = tk;
        end
    end
    % 计算阈值
    K_T = double(th)/255;
    % 二值化
    I2 = im2bw(I, K_T);
    % 存储
    I_out(:,:,ik) = I2;
    % 显示
    axes(handles.axes2);
    imshow(I2, []);
    title('迭代阈值');
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('迭代阈值');
end

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
% 显示
axes(handles.axes1);
imshow(I_origin, []);
title('原图像');
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I = I_origin(:,:,ik);
    % OTSU方法计算归一化阈值
    level = graythresh(I);
    % 二值化图像
    I2 = im2bw(I, level);
    % 存储
    I_out(:,:,ik) = I2;
    % 显示
    axes(handles.axes2);
    imshow(I2, []);
    title('OSTU阈值');
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('OSTU阈值');
end

% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I_gray = I_origin(:,:,ik);
    % 维数
    [m,n] = size(I_gray);
    % 初始化
    T = zeros(m,n);
    % 参数
    M = 3;
    N = 3;
    % 数据类型转换
    I_gray = double(I_gray);
    for i = M+1:m-M
        for j = N+1:n-N
            % 初始化
            max = 1;
            min = 255;
            %当前像素周围的3*3区域中的最大值和最小值
            for k = i-M:i+M
                for l = j-N:j+N
                    if I_gray(k,l)>max
                        % 更新
                        max=I_gray(k,l);
                    end
                    if I_gray(k,l)
                        % 更新
                        min=I_gray(k,l);
                    end
                end
            end
            %T矩阵用来记录每点像素的阈值
            T(i,j)=(max+min)/2;
        end
    end
    % 初始化
    I_bw=zeros(m,n);
    for i=1:m
        for j=1:n
            if I_gray(i,j) > T(i,j)
                % 达到阈值
                I_bw(i,j) = 255;
            else
                % 背景
                I_bw(i,j)=0;
            end
        end
    end
    % 存储
    I_out(:,:,ik) = I_bw;
    % 显示
    axes(handles.axes2);
    imshow(I_bw, []);
    title('Bernsen阈值');
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('Bernsen阈值');
end

% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I_gray = I_origin(:,:,ik);
    % 窗口参数
    K = [5, 5];
    % 维数
    mysize = size(I_gray);
    % 个数
    m = fix(mysize(1)/K(1));
    n = fix(mysize(2)/K(2));
    % 初始化
    z = zeros(mysize(1),mysize(2));
    for i = 1 : K(1)
        for j = 1 : K(2)
            % 方块处理
            Idiv{i,j} = I_gray((i-1)*m+1:i*m,(j-1)*n+1:j*n);
            I_th(i,j) = graythresh(Idiv{i,j})*255;
            Image_C{i,j} = ones(m,n)*I_th(i,j);
        end
    end
    % 第一次平滑过渡
    for i = 1:K(1)
        I_M = [];
        for j = 1:K(2)-1
            % 平滑过渡
            r1 = linspace(I_th(i,j),I_th(i,j+1),n);
            Image_C{i,j} = ones(m,1)*r1;
            I_M = [I_M,Image_C{i,j}];
        end
        % 存储
        Image_C1{i,:}=[I_M,Image_C{i,j+1}];
    end
    % 第二次平滑过渡
    Image_C3=[];
    for i = 1 : K(1)-1
        % 读取
        I1 = Image_C1{i};
        I2 = Image_C1{i+1};
        L1 = I1(1,1:end);
        L2 = I2(1,1:end);
        % 初始化
        Image_C2 = [];
        for j = 1:length(L1)
            % 平滑过渡
            Lj = linspace(L1(j),L2(j),m);
            Lj = Lj';
            Image_C2 = [Image_C2,Lj];
        end
        % 存储
        Image_C3 = [Image_C3;Image_C2];
    end
    % 整合
    Image_C3 = [Image_C3;Image_C1{i+1}];
    % 初始化
    I_Image = I_gray(1:size(Image_C3,1),1:size(Image_C3,2));
    for i = 1:size(Image_C3,1)
        for j = 1:size(Image_C3,2)
            if I_Image(i,j) >= Image_C3(i,j)
                % 设置背景
                I_Image(i,j) = 0;
            else
                % 设备前景
                I_Image(i,j) = 255;
            end
        end
    end
    % 显示
    axes(handles.axes2);
    imshow(I_Image, []);
    title('阈值插值法分割');
    % 存储
    I_out(:,:,ik) = I_Image;
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('阈值插值法分割');
end


% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    afm = I_origin(:,:,ik);
    % 算子
    se = strel('disk', 15);
    % 高低帽变换
    Itop = imtophat(afm,se);
    Ibot = imbothat(afm,se);
    % 增强
    Ienhance =imsubtract(imadd(Itop,afm), Ibot);
    % 取反
    Iec = imcomplement(Ienhance);
    % 分水岭变换
    wat = watershed(Iec);
    % 去除边缘
    wat = mat2gray(afm) - mat2gray(wat);
    % 归一化
    wat = mat2gray(wat);
    % 显示
    axes(handles.axes2);
    imshow(wat, []);
    title('水线阈值法分割');
    % 存储
    I_out(:,:,ik) = wat;
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('水线阈值法分割');
end

% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I_in = I_origin(:,:,ik);
    % 数据类型转换
    I_in = im2double(I_in);
    % 维数
    [M,N] = size(I_in);
    % 初始化位置
    Position = [123 35];
    % 横坐标取整
    x = round(Position(2));
    % 纵坐标取整
    y = round(Position(1));
    % 将生长起始点灰度值存入seed中
    seed = I_in(x,y);
    % 作一个全零与原图像等大的图像矩阵,作为输出图像矩阵
    I_out = zeros(M,N);
    % 将I_out中与所取种子点相对应的位置设置为1,即种子区域设置为白色
    I_out(x,y) = 1;
    % 储存符合区域生长条件的点的灰度值的和
    sm = seed;
    % 储存符合区域生长条件的点的个数
    suit = 1;
    % 记录每次判断一点周围八点符合条件的新点的数目
    count = 1;
    % 阈值,注意需要和double类型存储的图像相符合
    threshold = 0.2;
    while count > 0
        % 记录判断一点周围八点时,符合条件的新点的灰度值之和
        s = 0;
        count = 0;
        for i = 1:M
            for j = 1:N
                if I_out(i,j) == 1
                    % 判断此点是否为图像边界上的点
                    if (i-1)>0 && (i+1)<(M+1) && (j-1)>0 && (j+1)<(N+1)
                        % 判断点周围八点是否符合阈值条件
                        for u = -1:1
                            for v = -1:1
                                if I_out(i+u,j+v)==0 && abs(I_in(i+u,j+v)-seed)<=threshold && 1/(1+1/15*abs(I_in(i+u,j+v)-seed))>0.8
                                    I_out(i+u,j+v) = 1;
                                    % 判断是否尚未标记,并且为符合阈值条件的点
                                    % 符合以上两条件即将其在J中与之位置对应的点设置为白
                                    count = count+1;
                                    % 此点的灰度之加入s中
                                    s = s+I_in(i+u,j+v);
                                end
                            end
                        end
                    end
                end
            end
        end
        % 将n加入符合点数计数器中
        suit=suit+count;
        % 将s加入符合点的灰度值总合中
        sm=sm+s;
        % 计算新的灰度平均值
        seed=sm/suit;
    end
    % 显示
    axes(handles.axes2);
    imshow(I_out, []);
    title('区域生长分割');
    % 存储
    I_outs(:,:,ik) = I_out;
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_outs = mat2gray(I_outs);
    imshow(I_outs, []);
    title('区域生长分割');
end

% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.I_origin, 0)
    % 如果没有图像
    return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
    % 逐层处理
    I = I_origin(:,:,ik);
    % 分解
    S = qtdecomp(I, 0.27);
    % 初始化
    blocks = repmat(uint8(0),size(S));
    for dim = [512 256 128 64 32 16 8 4 2 1];
        % 处理每一个分块
        numblocks = length(find(S==dim));
        if (numblocks > 0)
            % 迭代赋值
            values = repmat(uint8(1),[dim dim numblocks]);
            values(2:dim,2:dim,:) = 0;
            blocks = qtsetblk(blocks,S,dim,values);
        end
    end
    % 处理边界
    blocks(end,1:end) = 1;
    blocks(1:end,end) = 1;
    % 显示
    axes(handles.axes2);
    imshow(blocks, []);
    title('四叉树分解');
    % 存储
    I_out(:,:,ik) = blocks;
end
if ndims(I_origin) == 3
    % 显示RGB图像
    axes(handles.axes2);
    % 归一化
    I_out = mat2gray(I_out);
    imshow(I_out, []);
    title('四叉树分解');
end

% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 退出对话框
choice = questdlg('确定要退出系统?', ...
    '退出', ...
    '确定','取消','取消');
switch choice
    case '确定'
        close;
    case '取消'
        return;
end

在这里插入图片描述

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-05-07 11:11:00  更:2022-05-07 11:12:02 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 7:25:57-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码