0
votes

Hi I have a set of images of size 200x200 and I want to divide these images into 10 blocks of size 20x20(each image). After the images are divided into blocks,

1) I want to compare 1st block of image 1 with 1st block of image2, image 3 and 2nd block with 2nd block of image2, image 3 and so on.

2)After comparing blocks the block with maximum value should be used and put in a final image such that the final image has blocks with maximum value from image1, image2 or image3.

Is it possible to do such comparison and produce a new image.

image = cv2.resize(im,(200,200))
image1 = cv2.resize(im1,(200,200))

hs = round(h/10)
ws = round(w/10)
hs1 = round(hs1/10)
ws1 = round(ws1/10)
resized = cv2.resize(image, (ws,hs), interpolation = cv2.INTER_AREA)
resized1 = cv2.resize(image1, (ws1,hs1), interpolation = cv2.INTER_AREA)

The result is like as shown in the picture here

Images can be accessed here.

1
If you divide a 200x200 image into 20x20 blocks, you will get 100 blocks, not 10, surely? Please add a couple of the images to your question and an indication of what the result should look like.Mark Setchell
How do you compare a 20x20 block with another one? That's 400 pixels, or 1,200 values if the image is RGB, so what are you actually comparing and what will the result be?Mark Setchell
I want to compare the blocks with other blocks. I am able to compare the images pixel by pixel(pixel intensities). But I want to compare the blocks. One approach I thought was to take a mean of each block and compare it with all the corresponding blocks of the images. But I am not sure how to do that.Newbie
I have added some information to my answer - is that how you expect the result to look?Mark Setchell
@MarkSetchell is it possible to produce the output image as the original images. This is what i got when I used numpy.maximum.reduce() . But i was expecting that after the comparison the final image would be like the original images(like a normal image)Newbie

1 Answers

0
votes

A hint to get you started... you don't need to tile your image up and create resized/cropped sub-images to do this. You can perfectly easily access your blocks in situ. Here is an example, with smaller blocks (so you can see them) to get you started.

import numpy as np

# Make synthetic ramp image
ramp = np.arange(6,dtype=np.uint8).reshape(-1,1) + (np.arange(8)*10).reshape(1,-1)

That looks like this:

array([[ 0, 10, 20, 30, 40, 50, 60, 70],
       [ 1, 11, 21, 31, 41, 51, 61, 71],
       [ 2, 12, 22, 32, 42, 52, 62, 72],
       [ 3, 13, 23, 33, 43, 53, 63, 73],
       [ 4, 14, 24, 34, 44, 54, 64, 74],
       [ 5, 15, 25, 35, 45, 55, 65, 75]])

Now let's look at the top-left 2 rows and 3 columns:

print(ramp[:2, :3]) 

That looks like this:

array([[ 0, 10, 20],
       [ 1, 11, 21]])

And let's get their average:

print(ramp[:2, :3].mean())
10.5

Now let's look at the bottom-right 2 rows and 3 columns:

print(ramp[-2:, -3:])

array([[54, 64, 74],
       [55, 65, 75]])

And get their mean:

print(ramp[-2:, -3:].mean())
64.5

A second hint... your answer will look like this:

enter image description here