1

I am researching about ways of detecting changes in grayscale levels in images, but only working within a certain area of them, and I have come across the integral image. I think it can be used for this, just selecting an area from the image and comparing the mean gray level (or something like that) with other areas.

But my question is, is it possible (or is there a way) to compute the integral image of just the specific region I am interested in of the general image (the important region is mixed in different parts of the general image).

Cheers

Tonechas
  • 13,398
  • 16
  • 46
  • 80
  • I understand you've tagged this with python, but you could do this in MATLAB using: 'I = imread('cameraman.tif'); J = integralImage(I(1:50,1:50))' where 1:50, 1:50 is the ROI. My guess is that there must be something similar in python, especially in the openCV API: https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#integral – akamath Jan 02 '18 at 14:08
  • You question is confusing. Suggest you rephrase. Is your ROI fixed in the image canvas? If yes, then using the integral image does not give you any improvements. If not then it helps only if you compare against a "reference" image that never changes, or changes rarely compared to a "current" one. – Francesco Callari Jan 02 '18 at 16:24
  • Yes, my idea was to compare the image with a reference which always has a known level of gray. Sorry about the confusions. About the ROI it is always changing – Adrián Arroyo Perez Jan 03 '18 at 20:16

1 Answers1

2

I don't think the integral image is the most adequate tool for this task. Detection of intensity changes in a ROI can be easily implemented by comparing the intensity values within the ROI through Numpy's any and slicing as shown below.

To begin with, we import the necessary modules and load some sample images:

import numpy as np
from skimage import io
import matplotlib.pyplot as plt

reference = io.imread('https://i.stack.imgur.com/9fmvl.png')
same = io.imread('https://i.stack.imgur.com/u1wlT.png')
changed = io.imread('https://i.stack.imgur.com/H2dIu.png')

This is how the images look:

fig, [ax0, ax1, ax2] = plt.subplots(1, 3)
ax0.imshow(reference)
ax0.axis('off')
ax0.set_title('Reference')
ax1.imshow(same)
ax1.axis('off')
ax1.set_title('Same')
ax2.imshow(changed)
ax2.axis('off')
ax2.set_title('Changed')
plt.show(fig)

Sample images

Then we define a function that returns True whenever there is at least one ROI pixel whose intensity in the test image is different to that of the reference image:

def detect_change(ref, img, roi):
    upper, left, lower, right = roi
    return np.any(ref[upper:lower, left:right] != img[upper:lower, left:right])

Finally we just need to set up the ROI (the red square) and call detect_change with proper arguments:

In [73]: roi = [32, 32, 96, 96]

In [74]: detect_change(reference, same, roi)
Out[74]: False

In [75]: detect_change(reference, changed, roi)
Out[75]: True
Tonechas
  • 13,398
  • 16
  • 46
  • 80