如何去除图片左边缘的这条亮线?

问题描述 投票:0回答:1

我想从 bin 文件创建图像。一代之后我注意到左边有一条白线。创建的图像还可以,但我认为白线减少了图片的动态范围,小值不太明显。

Python 中的代码可以让我创建图像:

import matplotlib.pyplot as plt
import numpy as np
import time
from PIL import Image
import math
import numpy as np
import json
import pickle
import matplotlib.cm as cm
import PIL.ImageOps
#from libtiff import TIFFfile, TIFFimage
import tifffile

def micronToStep(v):
    #approximately 62nm/step
    return round((v * 1000)/62)

def normalizeData(data):
    return (data - np.min(data)) / (np.max(data) - np.min(data))

def moving_average(x, w):
    return np.convolve(x, np.ones(w), 'valid') / w

def annot_max(x,y, ax=None):
    xmax = x[np.argmax(y)]
    ymax = y.max()
    text= "x={:.3f}, y={:.3f}".format(xmax, ymax)
    if not ax:
        ax=plt.gca()
    bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
    arrowprops=dict(arrowstyle="->",connectionstyle="angle,angleA=0,angleB=60")
    kw = dict(xycoords='data',textcoords="axes fraction",
              arrowprops=arrowprops, bbox=bbox_props, ha="right", va="top")
    ax.annotate(text, xy=(xmax, ymax), xytext=(0.94,0.96), **kw)


fo = open('saveData2.bin', 'rb')
data = pickle.load(fo)
fo.close()


print("xyStep: ", data['xyStep'])
print("xRange: ", data['xRange'])
print("yRange: ", data['yRange'])
print("zRange: ", data['zRange'])
print("zBase: ", data['zBase'])

dimX = math.ceil(data['xRange'] / data['xyStep'])
dimY = math.ceil(data['yRange'] / data['xyStep'])
print(dimX, dimY)
img = np.zeros((dimX, dimY)).astype('uint16')

zRange = data['zRange']
imgData = data['data']
minValue = 999999999
maxValue = -999999999


for i in range(0, dimX):
    for j in range(0, dimY):
        if type(imgData[i][j]) is np.ndarray:

            try:
                smoothed = moving_average(imgData[i][j], 10)
                height = smoothed.argmax() # / smoothed.shape[0]) * zRange
            except TypeError:
                height = 0

            #if imgData[i][j] is None:
            #    height = 0
            #    print("none", i,j)
            #else:
            #    height = imgData[i][j].argmax()

            img[i][j] = height
            minValue = min(minValue, height)
            maxValue = max(maxValue, height)
            
           
print("Min: ", minValue)
print("Max: ", maxValue)


tifffile.imwrite('saveData2.tif', img)

创建的图像如下所示:

左边有一条白线,它的长度是图片的长度,宽度是一个像素。

问题是如何在处理时将其去除以增加图片其他部分的动态范围?

python image numpy image-processing multidimensional-array
1个回答
0
投票

只是扩展克里斯托夫的评论。

用以下方法切断最左边的列:

im = im[:, 1:]

将最左边的列归零:

im[:, 0] = 0
© www.soinside.com 2019 - 2024. All rights reserved.