💥💥💥💥💥💥💞💞💞💞💞💞💞💞欢迎来到海神之光博客之家💞💞💞💞💞💞💞💞💥💥💥💥💥💥
✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进;
🍎个人主页:海神之光
🏆代码获取方式:
海神之光Matlab王者学习之路—代码获取方式
⛳️座右铭:行百里者,半于九十。
更多Matlab图像处理仿真内容点击👇
①Matlab图像处理(进阶版)
②付费专栏Matlab图像处理(初级版)
⛳️关注优快云海神之光,更多资源等你来!!
⛄一、图像分割简介
理论知识参考:【基础教程】基于matlab图像处理图像分割【含Matlab源码 191期】
⛄二、部分源代码
function susanseg
clear all; close all; clc
image= imread(‘cell.jpg’);
% 用SUSAN算法进行边缘检测
image = susan(image,4);
figure, imshow(image,[]);
%imwrite(image, ‘./susanout/susanout.jpg’);
% 将image转为二值图像保存后,用图像处理工具
% 把其背景的所有连通区域处理为黑色,即只有细
% 胞体是白色,便于细胞数目的搜索
BW = im2bw(image, graythresh(image));
bounder_area = length(find(BW==0));
%imwrite(BW, ‘./susanout/bw.jpg’);
figure, imshow(BW);
% 申明全局变量
global B Dir m n;
B = imread(‘./blackbackground.jpg’);
B = im2bw(B, graythresh(B));
[m,n] = size(B);
figure, imshow(B);
% 细胞的总面积,即细胞所占的像素数目,包括细胞的边界
% 由于SUSAN提取出的边界已被增宽,所以将边界像素数除以2
% 来作为细胞的边界像素数目
total_area = length(find(B==1)) + bounder_area/2;
NUM = 5; % 细胞面积阈值
count = 0; % 细胞总数
% 搜索方向向量,4邻域搜索
Dir = [-1 0; 0 1; 1 0; 0 -1;];
% 搜索方向向量,8邻域搜索
%Dir = [-1 0; -1 1; 0 1; 1 1; 1 0; 1 -1; 0 -1; -1 -1;];
for i = 1:m
for j = 1:n
if B(i,j)==1 % 是细胞像素
num = search(i,j,4) + 1; % 计算该细胞的像素数目
if num>NUM
count = count + 1;
else
total_area = total_area - num; % 减掉不是细胞的面积
end
end
end
end
%fid = fopen(‘./susanout/results.txt’, ‘wt’);
fprintf(‘图像尺寸: %d * %d, SUSAN阈值: 4, 细胞面积阈值: %d\n’, …
n, m, NUM);
fprintf(‘细胞总数: %d, 细胞总面积: %.2f, 平均细胞面积: %.2f\n’, …
count, total_area, total_area/count);
%fprintf(fid,‘图像尺寸: %d * %d, SUSAN阈值: 4, 细胞面积阈值: %d\n’, …
% n, m, NUM);
%fprintf(fid,‘细胞总数: %d, 细胞总面积: %.2f, 平均细胞面积: %.2f\n’, …
% count, total_area, total_area/count);
%fclose(fid);
end
% -----------------------------------------------------------------------
%
% This function uses the SUSAN algorithm to find edges within an image
%
%
% >>image_out = susan(image_in,threshold)
%
%
% Input parameters … The gray scale image, and the threshold
% image_out … (class: double) image indicating found edges
% typical threshold values may be from 10 to 30
%
%
%The following steps are performed at each image pixel:
% ( from the SUSAN webpage, http://www.fmrib.ox.ac.uk/~steve/susan/susan/node4.html )
%
% Place a circular mask around the pixel in question.
% Calculate the number of pixels within the circular mask which have similar brightness to
% the nucleus. These define the USAN.
% Subtract USAN size from geometric threshold to produce edge strength image.
%
% Estimating moments to find the edge direction has not been implemented .
% Non-maximal suppresion to remove weak edges has not been implemented yet.
%
% example:
%
% >> image_in=imread(‘test_pattern.tif’);
% >> image = susan(image_in,27);
% >> imshow(image,[])
%
%
% Abhishek Ivaturi
%
% -------------------------------------------------------------------------
function image_out = susan(im,threshold)
% check to see if the image is a color image…
%im= imread(‘test_pattern.tif’)
%threshold=27;
d = length(size(im));
if d3
image=double(rgb2gray(im));
elseif d2
image=double(im);
end
% mask for selecting the pixels within the circular region (37 pixels, as
% used in the SUSAN algorithm
mask = ([ 0 0 1 1 1 0 0 ;0 1 1 1 1 1 0;1 1 1 1 1 1 1;1 1 1 1 1 1 1;1 1 1 1 1 1 1;0 1 1 1 1 1 0;0 0 1 1 1 0 0]);
% the output image indicating found edges
R=zeros(size(image));
% define the USAN area
nmax = 3*37/4;
% padding the image
[a b]=size(image);
new=zeros(a+7,b+7);
[c d]=size(new);
new(4:c-4,4:d-4)=image;
for i=4:c-4
for j=4:d-4
current_image = new(i-3:i+3,j-3:j+3);
current_masked_image = mask.*current_image;
% Uncomment here to implement binary thresholding
% current_masked_image(find(abs(current_masked_image-current_masked_image(4,4))>threshold))=0;
% current_masked_image(find(abs(current_masked_image-current_masked_image(4,4))<=threshold))=1;
% This thresholding is more stable
current_thresholded = susan_threshold(current_masked_image,threshold);
g=sum(current_thresholded(:));
if nmax<g
R(i,j) = g-nmax;
else
R(i,j) = 0;
end
end
end
⛄三、运行结果
⛄四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 赵勇,方宗德,庞辉,王侃伟.基于量子粒子群优化算法的最小交叉熵多阈值图像分割[J].计算机应用研究. 2008,(04)
3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除
🍅 仿真咨询
1 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化
2 机器学习和深度学习方面
卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
3 图像处理方面
图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知
4 路径规划方面
旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、车辆协同无人机路径规划、天线线性阵列分布优化、车间布局优化
5 无人机应用方面
无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配
6 无线传感器定位及布局方面
传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化
7 信号处理方面
信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化
8 电力系统方面
微电网优化、无功优化、配电网重构、储能配置
9 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长
10 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合