在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
labelme_to_dataset 指令的代码实现: show.py文件 #!E:\Anaconda3\python.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() 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:\Users\Fourmi\Desktop\result5.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;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论