资讯详情

python+matlab 3通道图像加横纵坐标和0-255色标

目的:可视化输入3通道图像,实现横纵坐标和色标操作,其中色标范围为0-255,但输入图像不灰度化。

步骤:

1、用python中的convert该方法将3通道转换为1通道

python代码:

def RGBtoGray(path):     files = os.listdir(path)     for file in files:         imgpath = path   '/'   file         # print(imgpath)         #         im = Image.open(imgpath).convert('L')         #resize将图像像素转换为您需要的像素大小         img = im.resize((100, 100))         dirpath = newpath         # file_name, file_extend = os.path.splitext(files)         # dst = os.path.join(os.path.abspath(dirpath), file_name   '.jpg')         img.save('D:/code/welddata/testimage/test/1.jpg') if __name__ == "__main__":     RGBtoGray(path)

2、用matlab画1通道灰度图的色标

Matlab代码:

clear all I = imread('E:\Matlab2019a\bin\tu01.png'); #读入图片  I = im2double(I);  dataRangeI = [min(I(:)) max(I(:))]  h = [1 2 1; 0 0 0; -1 -2 -1];  J = imfilter(I,h);  dataRangeJ = [min(J(:)) max(J(:))]  imshow(J,[])  colormap(gray);       #坐标图 colorbar;             #加色标 caxis(0,255]); axis('on');

代码结果:

标签: 色标传感器wm03nct2a色标光电传感器红外线电梯光幕

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台