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