php中文网 | cnphp.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 265|回复: 0

OTSU分割

[复制链接]

2616

主题

2623

帖子

9286

积分

管理员

Rank: 9Rank: 9Rank: 9

UID
1
威望
0
积分
6548
贡献
0
注册时间
2021-4-14
最后登录
2024-4-20
在线时间
665 小时
QQ
发表于 2022-11-24 18:08:35 | 显示全部楼层 |阅读模式
[mw_shl_code=applescript,true]function main_script()
    clc;

    addpath('./implementation')

    result_matrix = zeros(10,6);
    threshold_matrix = zeros(10,6);

    for i = 0 : 9
        I = imread(['./data/sample' num2str(i) '.tif']);

        h = entropy_otsu(I);
        result_matrix(i+1,1) = pixel_count(I, h);
        threshold_matrix(i+1,1) = h;

        h = my_otsu(I);
        result_matrix(i+1,2) = pixel_count(I, h);
        threshold_matrix(i+1,2) = h;

        h = valley_emphasis(I);
        result_matrix(i+1,3) = pixel_count(I, h);
        threshold_matrix(i+1,3) = h;

        h = neighbor_valley_emphasis(I,5);
        result_matrix(i+1,4) = pixel_count(I, h);
        threshold_matrix(i+1,4) = h;

        h = gaussian_valley_emphasis(I,5);
        result_matrix(i+1,5) = pixel_count(I, h);
        threshold_matrix(i+1,5) = h;

        h = lda_valley_emphasis(I);
        result_matrix(i+1,6) = pixel_count(I, h);
        threshold_matrix(i+1,6) = h;
    end
   
    fprintf('Table 1. Pixel counts of defect regions.\n')
    fprintf([repmat('-',1,70) '\n'])
    fprintf('Image #   Proposed method  Valley-emphasis  Neighbor-VE  Fisher''s LDA\n');
    fprintf([repmat('-',1,70) '\n'])
    for i = 1 : 10
        fprintf([num2str(i) '\t  ' ...
                 num2str(result_matrix(i,1)) '\t\t   ' ...
                 num2str(result_matrix(i,3)) '\t\t    ' ...
                 num2str(result_matrix(i,4)) '\t\t ' ...
                 num2str(result_matrix(i,6)) '\n']);
    end
    fprintf([repmat('-',1,70) '\n\n'])
   
    fprintf('Table 2. Output thresholds.\n')
    fprintf([repmat('-',1,70) '\n'])
    fprintf('Image #   Proposed method  Valley-emphasis  Neighbor-VE  Fisher''s LDA\n');
    fprintf([repmat('-',1,70) '\n'])
    for i = 1 : 10
        fprintf([num2str(i) '\t  ' ...
                 num2str(threshold_matrix(i,1)) '\t\t   ' ...
                 num2str(threshold_matrix(i,3)) '\t\t    ' ...
                 num2str(threshold_matrix(i,4)) '\t\t ' ...
                 num2str(threshold_matrix(i,6)) '\n']);
    end
    fprintf([repmat('-',1,70) '\n'])

    rmpath('./implementation')

end

function output = pixel_count( img, threshold )

    img = im2bw(img, threshold/255);

    % if the thresholded image is mainly black, white pixels are supposed
    % to be abnormal, and vice versa
    if sum(sum(img == 0)) > sum(sum(img == 1))
        output =  sum(sum(img == 1));
    else
        output =  sum(sum(img == 0));
    end

end
[/mw_shl_code]





上一篇:二维数组的查表法
下一篇:16QAM调制解调及误码率分析仿真程序
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|php中文网 | cnphp.com ( 赣ICP备2021002321号-2 )51LA统计

GMT+8, 2024-4-20 14:07 , Processed in 0.213924 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

申明:本站所有资源皆搜集自网络,相关版权归版权持有人所有,如有侵权,请电邮(fiorkn@foxmail.com)告之,本站会尽快删除。

快速回复 返回顶部 返回列表