I=imread('rice.png');
subplot(2,4,1),imshow(I,[]);
thresh=graythresh(I);%自适应确定阈值
thresh=0.5137;
Ibw=im2bw(I,thresh)
subplot(2,4,2),imshow(Ibw,[]);
subplot(2,4,3),surf(double(I(1:8:end,1:8:end))),zlim([0 255]),colormap gray;%显示I的3维可视化效果
bg=imopen(I,strel('disk',15));%半径为15的圆形结构元素进行灰度开运算提取背景曲面
subplot(2,4,4),surf(double(bg(1:8:end,1:8:end))),zlim([0 255]),colormap gray; %显示背景曲面的三维可视化效果
Itophat=imsubtract(I,bg);%顶帽变换
subplot(2,4,5),imshow(Itophat);
subplot(2,4,6),surf(double(Itophat(1:8:end,1:8:end))),zlim([0 255]);%显示顶帽变换的三维可视化效果
I2=imadjust(Itophat);%对比度拉伸
subplot(2,4,7),imshow(I2);
thresh2=graythresh(I2)%自适应确定阈值
thresh2=0.4843
Ibw2=im2bw(I2,thresh2);
subplot(2,4,8),imshow(Ibw2);

顶帽变换

第一幅图是matlab自带的米粒图像,相对高灰度的米粒分散于整体的暗背景中,注意到图像上半部分的背景明显要比下部的背景区域亮一些,这正是由成像时不均匀的光照引起的。操作者希望能通过阈值化把物体与背景分离开来,从而进一步研究物体的性质,如个数和位置关系等。

相关文章:

  • 2022-12-23
  • 2021-06-17
  • 2022-02-15
  • 2021-04-06
  • 2021-12-05
  • 2021-08-17
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2021-10-17
  • 2021-09-19
  • 2021-08-23
  • 2022-01-02
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案