0

I am subtracting the mean value of the image to each pixel using the following code (hopefully I am doing it right):

for filename in glob.glob('video//frames//*.png'):

    img = cv2.imread(filename,0)    

    values_list.append(img[150,:]) #Get all rows at x-axis 17 which is the row pixels
    values_mean.append(np.round(np.mean(img[150,:]), decimals=0)) 


output = np.array(values_list)
values_mean = np.array(values_mean).reshape(-1,1)
new_column_value = values_mean - output

When I plot the graph, I get

enter image description here

What is the best way to deal with negative values? Should I simply add an if statement if goes above 255 or below 0 to make it 0? but them someone mentioned "...you kill information on where the negatives are.." so how to deal with this correctly ?

I intend to calculate the shift value between frames by getting the maximal correlation value of the subtracted image, and comparing it to the adjacent frame

There are countless similar questions, but cannot find a solid ground here, here, here, here....etc

PolarBear10
  • 2,065
  • 7
  • 24
  • 55
  • *"What is the best way to deal with negative values?"* If you subtract the mean from a set of numbers, *of course* you will get some negative values. I don't think anyone can answer your question without knowing why you are doing this subtraction. What are you going to do with the result? Do the subsequent steps not allow negative values? You say *"I intend to calculate the shift in value between the frames"*, but what does that mean? Shift in what value? – Warren Weckesser Mar 16 '20 at 06:54
  • @WarrenWeckesser, I intend to calculate the shift value between frames by getting the maximal correlation value of the `subtracted image`, and comparing it to the adjacent frame – PolarBear10 Mar 16 '20 at 06:58
  • So perhaps you could cast your arrays to a signed type before doing the subtraction, either a signed integer or even floating point. – Warren Weckesser Mar 16 '20 at 07:00

1 Answers1

1

If you're trying to determine "how far away from the mean is a given pixel", then wouldn't it make more sense to take the absolute value of your result?

new_column_value = np.absolute(values_mean - output)
Oliver.R
  • 1,282
  • 7
  • 17