从一组多张图像中减去一个共同的背景

subtract a common background from a set of multiple images

提问人:vashista 提问时间:5/30/2022 最后编辑:Christoph Rackwitzvashista 更新时间:5/31/2022 访问量:284

问:

我必须从一系列图像(图像数量 = 250,也是 16 位 tiff)中删除背景(16 位 tiff 图像),如实际图主示例图像所示(主图像的 jpg 已上传)。我编写了以下代码来执行相同的操作,但减法部分无法正常工作。生成的图像在角落(极亮像素)处的计数为 5000,如图所示,减减去(上传生成图像的 jpg)。请让我知道此代码中的问题所在。

#read image series 
S01=[i for i in glob.glob("C:/Users/experiment 2/S01/*.tif")] #16 bit tiff main image
S02=[i for i in glob.glob("C:/Users/experiment 2/S02/*.tif")] #16 bit tiff background image

#average the background 
bg=np.array([np.array(Image.open(fname)) for fname in S02])
bg_avg=np.array(np.mean(bg,axis=(0)),dtype=np.uint16)
bg_out=Image.fromarray(bg_avg) #image to plot using imshow

#remove background image from each of the main image
main=np.array([np.array(Image.open(fname)) for fname in S01]) #(has maximum of 1200)
main_sub=np.subtract(main,bg_avg) # i am not sure if this line in the code is actually subtracting background from the series of main image
main_avg=np.array(np.mean(main_sub,axis=(0)),dtype=np.uint16) 
main_out=Image.fromarray(flame_avg) #(has maximum of 5000)

Plt.figure
subplot(1,2,1)
plt.imshow(main_out)
subplot(1,2,2)
plt.imshow(bg_out)

plt.show()
python numpy 图像处理 python 成像库

评论

0赞 Mark Setchell 5/31/2022
请提供人们可以使用的实际的、单独的图像,而不是带有轴并连接在一起的图像的图片/屏幕截图。谢谢。您可能需要 Dropbox 或 Google Drive 来获取 16 位 TIFF。
0赞 Christoph Rackwitz 5/31/2022
当你应该使用有符号的 int 时,你正在使用无符号int。负差异将环绕,因为您正在使用无符号整数。-- 如果值从未超过 32767,请使用 (或 dtype=np.int16),否则使用 int32.astype(np.int16)

答: 暂无答案