Matlab求出图像中每个细胞的细胞核与核仁面积之比代码

该博客主要介绍了使用MATLAB进行图像处理的方法,包括读取图像、灰度转换、二值化、形态学操作(开运算)、连通组件分析及区域属性计算,以实现细胞检测和分割。博客还探讨了如何识别并计算每个细胞内部的核仁区域,展示了详细的代码实现过程。
摘要由CSDN通过智能技术生成

clc;clear;close all;

img = imread(‘1.bmp’);
I = rgb2gray(img);
figure(1),imshow(I)

level =graythresh(I);
BW = im2bw(I,level);
se=strel(‘disk’,3’);%圆盘型结构元素
fo=imclose(BW,se);%直接开运算
BW2 = bwareaopen(1-fo, 200);
%计算各个连通体的中心
[lalels,NumTotal] = bwlabel(BW2);
centroid = regionprops(lalels,‘BoundingBox’,‘Area’,‘Centroid’);%重心
figure(2),
imshow(img)
hold on,
for i=1:length(centroid)
rectangle(‘Position’,centroid(i).BoundingBox, ‘LineWidth’, 2, ‘EdgeColor’,‘g’);
text(centroid(i).Centroid(1),centroid(i).Centroid(2),num2str(i),‘color’,‘r’,‘FontSize’,14)
end

% level2 =graythresh(I);
% BW3 = im2bw(I,0.52);
% figure(4),imshow(BW3)

% figure(3),
for i=1:length(centroid)
Irect = floor(centroid(i).BoundingBox);
ITmp = I(Irect(2):(Irect(2)+Irect(4)+1), Irect(1):(Irect(1)+Irect(3)+1));
leveltmp =graythresh(ITmp);
BWtmp = im2bw(ITmp,0.52);
if(all(BWtmp(:)==1))
continue;
end
BWtmp2 = bwareaopen(1-BWtmp, 3);
[lalelstmp,NumTotaltmp] = bwlabel(BWtmp2);
centroidtmp = regionprops(lalelstmp,‘Area’);%重心
disp(strcat(‘第’,num2str(i),‘个细胞的各个细胞核对核仁面积的占比为:’,num2str(sum([centroidtmp.Area]/centroid(i).Area))));
% imshow(BWtmp,[])
end
请添加图片描述
请添加图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值