目的:可视化输入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');
代码结果: