Using Python, I have to:
- Divide a
Test_Image
andReference_image
into 5x5 blocks, - Compute a histogram for each block, and compare it with the same block in the other image.
For Example:image1(1,1)
withimage2(1,1)
. - Compare the similarity between two images (should be transform invariant).
So far, I have calculated the histogram of the whole image using hist=numpy.histogram(image,bins=256)
I want to divide an image, and later compute the histogram for all those blocks . I also want to use Bhattacharya's coefficient to measure the similarity.
Can anyone guide me with how to go through this one? Thanks in advance :)
Not sure if it is something like this you are looking for, This is the brute-force version.and it's probably quite slow.but it does the job You have to decide what to do with the boundaries though. This will not include the boundary unless the window fits exactly
Below is the result and the full image is at the end. r,c represents the topleft corner of the window
If your images are large, you can improve performance by manipulating the array's strides to produce the windows you need. The following will use a generalized sliding window function found at Efficient Overlapping Windows with Numpy - I will include it at the end.
sliding window function(s):
If you want to divide an image into four parts, you need to calculate the
ws
andss
paramaters. If both dimensions are divisible by two thenws
andss
are the same value (ss
defaults tows
when not specified). Numpy has the ability to treat array dimensions as (column, row) or (row, column) - I haven't changed any defaults and mine is (row, column). For an 18x26 picture,ws = (26/2, 18/2)
- each window will be 13x9 and the adjacent windows are obtained by siliding the window by an equal amount, no overlap. If a dimension is not divisable by two,ss
will also need to be determined and there will be some overlap in the windows. For an 18x33 image:For 3d windows (data from images with a color dimension)
ws
andss
need to have three dimensions. A 15x15 image will have 9 5x5x3 windows