?? fengebaohe.m
字號:
function fengebaohe
origin=imread('cell.jpg');
hsv=rgb2hsv(origin);
%提取S分量
saturation=hsv(:,:,2);
%OTSU法選取閾值分割細胞核
level = graythresh(saturation);
bw1 = im2bw(saturation,level);
%種子填充
bw2 = imfill(bw1,'holes');
%腐蝕膨脹得到細胞核,次數可視實際情況而定
time=5; %腐蝕次數
bw3=bwmorph(bw2,'erode',time);
bw3=bwmorph(bw3,'dilate',time);
bw4=edge(uint8(bw3),'canny');
%在原始圖象上顯示細胞核輪廓
origin_add=origin;
[m n]=size(bw4);
for i=1:m
for j=1:n
if bw4(i,j)==1
origin_add(i,j,:)=255;
end
end
end
%連通域標記并計算細胞核質心
[L num]=bwlabel(bw3);
area=bwarea(bw3);
total_x=0;
total_y=0;
for i=1:m
for j=1:n
total_x=total_x+j*bw3(i,j);
total_y=total_y+i*bw3(i,j);
end
end
center_x=total_x/area;
center_y=total_y/area;
center_x=uint8(center_x);
center_y=uint8(center_y);
%計算細胞外部標識矩形的起始點
point_x=double(center_x)-90;
point_y=double(center_y)-90;
%分別顯示原圖,分割出的細胞核,疊加的細胞核,以及細胞外接矩形
figure,subplot(2,2,1),imshow(origin);
subplot(2,2,2),imshow(bw3);
subplot(2,2,3),imshow(origin_add);
subplot(2,2,4),imshow(origin);
rectangle('Curvature',[1,1],'Position',[point_x point_y 200 200]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -