【脑切片图像分割】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. 输出结果

脑切片图像分割结果

相关推荐
机器学习之心1 天前
LASSO回归+特征选择,MATLAB
matlab·数据挖掘·回归
一苓二肆1 天前
PUMA机械臂matlab仿真正逆解与路径规划
开发语言·matlab
leo__5201 天前
基于A星算法的MATLAB路径规划实现
人工智能·算法·matlab
一招定胜负1 天前
图像金字塔与直方图
图像处理·opencv·计算机视觉
叁散1 天前
实验项目4 光电式传感器原理与应用(基于Matlab)
开发语言·matlab
云雾J视界1 天前
GaN时代软开关设计不再玄学:MATLAB精准仿真ZVS边界条件,解决3.3kW电源啸叫难题
matlab·gan·llc·zvs·储能pcs·电荷守恒方程
slandarer1 天前
MATLAB | 如何使用MATLAB制作猫猫围棋小游戏
matlab·小游戏·围棋
AI即插即用1 天前
即插即用系列 | CVPR 2025 CATANet:一种用于轻量级图像超分辨率的高效内容感知 Token 聚合网络
图像处理·人工智能·深度学习·神经网络·计算机视觉·超分辨率重建
埃科光电1 天前
应用分享丨破解3C行业反光与弱缺陷检测难题
图像处理·数码相机·计算机视觉·制造·相机
子夜江寒1 天前
使用 OpenCV 实现银行卡卡号识别
图像处理·opencv·计算机视觉