• 将labelme 生成的.json文件进行可视化的代码+label.png 对比度处理的matlab代码


    labelme_to_dataset 指令的代码实现:

    show.py文件

    #!E:Anaconda3python.exe
    
    import argparse
    import json
    import os
    import os.path as osp
    
    import PIL.Image
    import yaml
    
    from labelme import utils
    
    
    def main():
        parser = argparse.ArgumentParser()
        parser.add_argument('json_file')
        args = parser.parse_args()
    
        json_file = args.json_file
    
        out_dir = osp.basename(json_file).replace('.', '_')
        out_dir = osp.join(osp.dirname(json_file), out_dir)
        os.mkdir(out_dir)
    
        data = json.load(open(json_file))
    
        img = utils.img_b64_to_array(data['imageData'])
        lbl, lbl_names = utils.labelme_shapes_to_label(img.shape, data['shapes'])
    
        lbl_viz = utils.draw_label(lbl, img, lbl_names)
    
        PIL.Image.fromarray(img).save(osp.join(out_dir, 'img.png'))
        PIL.Image.fromarray(lbl).save(osp.join(out_dir, 'label.png'))
        PIL.Image.fromarray(lbl_viz).save(osp.join(out_dir, 'label_viz.png'))
    
        info = dict(label_names=lbl_names)
    
        with open(osp.join(out_dir, 'info.yaml'), 'w') as f:
            yaml.safe_dump(info, f, default_flow_style=False)
    
        print('wrote data to %s' % out_dir)
    
    
    if __name__ == '__main__':
        main()

    调整label.png对比度matlab代码

    clc;
    close all;
    clear all;
     
    src_img = imread('C:\Users\Fourmi\Desktop\5_json\label.png');  
    
    figure (1) 
    subplot(321),imshow(src_img),title('原图像');%显示原始图像  
    subplot(322),imhist(src_img),title('原图像直方图');%显示原始图像直方图  
    
    matlab_eq=histeq(src_img);         %利用matlab的函数直方图均衡化
    subplot(323),imshow(matlab_eq),title('matlab直方图均衡化原图像');%显示原始图像  
    subplot(324),imhist(matlab_eq),title('matlab均衡化后的直方图');%显示原始图像直方图 
    
    dst_img=myHE(src_img);             %利用自己写的函数直方图均衡化
    subplot(325),imshow(dst_img),title('手写均衡化效果');%显示原始图像
    imwrite(dst_img,'C:UsersFourmiDesktop
    esult5.png')
    subplot(326),imhist(dst_img),title('手写均衡化直方图');%显示原始图像直方图 

    myHe.m 文件

    function dst_img=myHE(src_img)  
    
    [height,width] = size(src_img);
    dst_img=uint8(zeros(height,width));
    %进行像素灰度统计;    
    NumPixel = zeros(1,256);%统计各灰度数目,共256个灰度级    
    for i = 1:height    
        for j = 1: width    
            NumPixel(src_img(i,j) + 1) = NumPixel(src_img(i,j) + 1) + 1;%对应灰度值像素点数量增加一    
        end    
    end    
    %计算灰度分布密度    
    ProbPixel = zeros(1,256);    
    for i = 1:256    
        ProbPixel(i) = NumPixel(i) / (height * width * 1.0);    
    end    
    %计算累计直方图分布    
    CumuPixel = zeros(1,256);    
    for i = 1:256    
        if i == 1    
            CumuPixel(i) = ProbPixel(i);    
        else    
            CumuPixel(i) = CumuPixel(i - 1) + ProbPixel(i);    
        end    
    end    
      
    % 指定范围进行均衡化  
    % pixel_max=max(max(I));  
    % pixel_min=min(min(I));  
    pixel_max=255;  
    pixel_min=0;  
    %对灰度值进行映射(均衡化)    
    for i = 1:height    
        for j = 1: width    
            dst_img(i,j) = CumuPixel(src_img(i,j)+1)*(pixel_max-pixel_min)+pixel_min;    
        end    
    end    
    return;
    
    

  • 相关阅读:
    ubuntu>雷鸟只能收邮件不能发邮件
    ubuntu>安装jdk(转)
    ubuntu>修改root密码
    ios>Could not instantiate class named NSLayoutConstraint(转)
    ios>xcode4.5 如何找到以前的iphone模拟器(转)
    Windows7系统开始菜单改成经典样式
    ASP.NET多语言版的开发
    Dynamic repositories in LightSpeed
    Enhancing queries in dynamic repositories
    C# 4.0 Dynamic关键字全解析
  • 原文地址:https://www.cnblogs.com/fourmi/p/8874906.html
Copyright © 2020-2023  润新知