【脑切片图像分割】MATLAB 图像处理 源码

1. 简单图像处理

加载图像 Brain.jpg,使用直方图和颜色分割成区域这些区域有不同的颜色。 这是一个更高级的问题,有多个解决它的方法。

例如,您可以计算具有特定数字的图像的直方图(例如 16 - 32),找到直方图中最小值的位置(参见,例如,islocalmin)并对最小值之间的强度区域应用不同的颜色。这可以通过将强度值作为颜色查找表的索引来完成(例如 hsv 生成)并将强度值重新映射到此类(请参阅 ind2rgb)。 您可以还可以通过灰度强度来缩放颜色的强度。

2. MATLAB 源码

matlab 复制代码
% Load and show image
im = imread('brain.jpg');
im = rgb2gray(im);
figure(1);
clf;
subplot(1,3,1);
imshow(im);

% Histogram
bins = 24;
subplot(1,3,2);
[counts,idx] = imhist(im,bins);
plot(idx,counts);
axis tight;
% Find minima and make sure they are integers
minima = round(idx(islocalmin(counts))');
xline(minima);

% Color regions by mapping greyscale to colormap indices
colors = hsv(numel(minima)+1); % HSV colormap for base-color for region (over hue values only)
cc = 1;
p = 0;
map = zeros(256,3);
for l = [minima, 256] % cover index (intensity) ranges from p to l, including the last one to 256
  cidx = (p+1):l;
  for k = cidx % Loop for simplicity (instead of matrix operation)
    %map(k,:) = colors(cc,:);         % No scaling w.r.t original itensity
    %map(k,:) = colors(cc,:) * k/256; % Linearly scale color value w.r.t. original intensity
    map(k,:) = colors(cc,:) * (0.25 + (k-p-1)/(l-p-1)*0.75); % Different color itensity scaling
  end
  p = l;
  cc = cc + 1;
end
imc = ind2rgb(im,map);
subplot(1,3,3);
imshow(imc);

% Show ranges in histogram by overlaying colors (could be integrated in above loop)
subplot(1,3,2);
y1 = 0;
y2 = max(counts);
cc = 1;
p = 0;
for l = [minima,256]
  h = rectangle('Position', [p, 0, l-p, y2], ...
                'FaceColor', [colors(cc,:),0.3], ...
                'EdgeColor', [colors(cc,:),0.3]);
  p = l;
  cc = cc + 1;
end

3. 输出结果

脑切片图像分割结果

相关推荐
没有梦想的咸鱼185-1037-166313 小时前
MATLAB科研数据可视化技术
开发语言·机器学习·matlab·信息可视化·数据分析
民乐团扒谱机1 天前
【微实验】弦振动 MATLAB 物理模型 动画仿真
matlab·动画·仿真·信号·声学·振动·
Evand J1 天前
【matlab例程】无迹粒子滤波(UPF)的例程,用于三维环境下多雷达目标跟踪,非线性系统
开发语言·matlab·目标跟踪
AndrewHZ2 天前
【图像处理基石】如何对遥感图像进行实例分割?
图像处理·人工智能·python·大模型·实例分割·detectron2·遥感图像分割
琛:D3 天前
【MATLAB/Simulink】查看MATLAB以往版本的帮助文档
matlab
LeonDL1683 天前
【通用视觉框架】基于QT+Halcon开发的流程拖拽式通用视觉框架软件,全套源码,开箱即用
图像处理·visionmaster·qt+halcon·流程拖拽式通用视觉框架软件·通用视觉框架软件·机器视觉通用框架·easyvision
程序员老冯头3 天前
第三十二节 MATLAB函数
数据结构·算法·matlab
民乐团扒谱机3 天前
【微实验】圆周运动的正弦信号发生仿真及其衍生(三)
经验分享·matlab·仿真·信号与系统·声音·微实验
绿炮火3 天前
【MATLAB】(二)基础知识
开发语言·算法·matlab
88号技师3 天前
2025年6月最新SCI-灰熊脂肪增长优化算法Grizzly Bear Fat Increase-附Matlab免费代码
开发语言·人工智能·算法·matlab·优化算法