function [J, seed_point, ts] = Regiongrowing(I, seed_point)
% 统计耗时
t1 = cputime;
% 参数检测
if nargin < 2
% 显示并选择种子点
figure; imshow(I,[]); hold on;
seed_point = ginput(1);
plot(seed_point(1), seed_point(2), 'ro', 'MarkerSize', 10, 'MarkerFaceColor', 'r');
title('种子点选择');
hold off;
end
% 变量初始化
seed_point = round(seed_point);
x = seed_point(2);
y = seed_point(1);
I = double(I);
rc = size(I);
J = zeros(rc(1), rc(2));
% 参数初始化
seed_pixel = I(x,y);
seed_count = 1;
pixel_free = rc(1)*rc(2);
pixel_index = 0;
pixel_list = zeros(pixel_free, 3);
pixel_similarity_min = 0;
pixel_similarity_limit = 0.1;
% 邻域
neighbor_index = [-1 0;
1 0;
0 -1;
0 1];
% 循环处理
while pixel_similarity_min < pixel_similarity_limit && seed_count < rc(1)*rc(2)
% 增加邻域点
for k = 1 : size(neighbor_index, 1)
% 计算相邻位置
xk = x + neighbor_index(k, 1);
yk = y + neighbor_index(k, 2);
% 区域生长
if xk>=1 && yk>=1 && xk<=rc(1) && yk<=rc(2) && J(xk,yk) == 0
% 满足条件
pixel_index = pixel_index+1;
pixel_list(pixel_index,:) = [xk yk I(xk,yk)];
% 更新状态
J(xk, yk) = 1;
end
end
% 更新空间
if pixel_index+10 > pixel_free
pixel_free = pixel_free+pixel_free;
pixel_list(pixel_index+1:pixel_free,:) = 0;
end
% 统计迭代
pixel_similarity = abs(pixel_list(1:pixel_index,3) - seed_pixel);
[pixel_similarity_min, index] = min(pixel_similarity);
% 更新状态
J(x,y) = 1;
seed_count = seed_count+1;
seed_pixel = (seed_pixel*seed_count + pixel_list(index,3))/(seed_count+1);
% 存储位置
x = pixel_list(index,1);
y = pixel_list(index,2);
pixel_list(index,:) = pixel_list(pixel_index,:);
pixel_index = pixel_index-1;
end
% 返回结果
J = mat2gray(J);
J = im2bw(J, graythresh(J));
% 统计耗时
t2 = cputime;
ts = t2 - t1;


温柔-的-女汉子
- 粉丝: 1105
- 资源: 4311
最新资源
- 三菱FX3U与东元Teco N310变频器通讯实战程序:使用485方式Modbus RTU协议进行频率设定与读取.pdf
- 三菱FX3U与得利捷GD4430扫码枪通讯程序(SL3U-4):实现稳定可靠的串口通讯.pdf
- 三菱FX3U与东元Teco变频器通讯实战程序(含485通讯与Modbus RTU协议功能说明).pdf
- 三菱FX3U与力士乐VFC-x610变频器通讯程序及案例:含注释、程序、接线方式与设置.pdf
- 多领域仿真设计资源整合推荐-电子射频、单片机、机械工业及其他设计必备
- mc 框架本地(forge)
- 深度求索DeepSeek本地化部署指南:借助Ollama实现在Windows上的AI模型快速应用与实践
- 1-HTML基础知识HTML文档的基本概念PDF
- pyenv-win 3.1.1
- 三菱FX3U分切机程序:伺服速度力矩模式下的锥度与恒张力控制模板.pdf
- 三菱FX3U分切机程序:伺服速度与力矩模式下的锥度与恒张力控制模板.pdf
- 三菱FX3U分切机程序:伺服速度与力矩模式下的锥度与恒张力控制程序模板.pdf
- 三菱FX3U分切机程序:速度力矩模式下的锥度与恒张力控制模板.pdf
- 三菱FX3U分切机程序:锥度控制与恒张力模式的通用程序模板.pdf
- 三菱FX3U画五角星程序:变址与角度计算的学习资料.pdf
- 三菱FX3U开发板底层源码:支持RUN下载程序,注释读写,脉冲输出与定位指令全覆盖(含PLSY_PWM_PLSR_PLSV_DRVI_DRVA等指令,波特率自适应9600~115200).pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


