简体   繁体   English

在 Python 中使用 opencv 进行灰度缩放后颜色显示异常

[英]Color display abnormal after gray scaling using opencv in Python

I am trying to use Opencv in python to process digital pathology images.我正在尝试在 python 中使用 Opencv 来处理数字病理图像。 I convert the csv image into array and I want to convert the image to gray scale, here is my code:我将 csv 图像转换为数组,我想将图像转换为灰度,这是我的代码:

start = time.time()
slide = openslide.open_slide("/Users/mihaoyang/Desktop/Pathology_Images/348980_case2_CD4.svs")
level_count = slide.level_count
print('level_count = ', level_count)
[column, row] = slide.dimensions
print('dimensions = ', column, row)
[column0, row0] = slide.level_dimensions[0]
[column1, row1] = slide.level_dimensions[1]
[column2, row2] = slide.level_dimensions[2]
print('dimensions[0] = ', [column0, row0])
print('dimensions[1] = ', [column1, row1])
print('dimensions[2] = ', [column2, row2])

slide_level_downsamples = slide.level_downsamples[2]
print(slide_level_downsamples)


slide_downsamples = slide.get_best_level_for_downsample(20.0)
print(slide_downsamples)

slide_normal = numpy.array(slide.read_region((12000, 15500), 0, (500, 500)))
slide_gray = numpy.array(slide.read_region((12000, 15500), 0, (500, 500)).convert('L'))

After I run the code, the following image was obtained我运行代码后,得到了下图

在此处输入图片说明

Assuming you are using MatPlotLib to plot the image it looks like it is viridis colormap check them out here .假设您正在使用 MatPlotLib 绘制看起来像viridis颜色图的图像,请在此处查看它们 If you want to change the colormap to gray scale pass gray into plt.imshow() .如果你想在颜色表更改为灰度通grayplt.imshow()

ie IE

plt.figure()
plt.imshow(slide_gray, 'gray')
plt.show()

If you're not using matplotlib then that will still be your problem so check out the image plotting library documentation for changing colormaps.如果您不使用 matplotlib,那么这仍然是您的问题,因此请查看图像绘图库文档以更改颜色图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM