I am trying to split an image using image slicer in python and then apply histogram equalization on each of them and combine them back. I am able to split the images into smaller blocks and I can see them being updated but after stitching them together I end up with the same image as the original one. Can someone point out what I am doing wrong. The file name is watch.png
import cv2
import numpy as np
from matplotlib import pyplot as plt
from scipy.misc import imsave
# import scipy
from scipy import ndimage
from scipy import misc
import scipy.misc
import scipy
import sys
import argparse
import image_slicer
from image_slicer import join
img = 'watch.png'
num_tiles = 64
tiles = image_slicer.slice(img, num_tiles)
file = "watch"
k = 0
filelist =[]
for i in range(1,9):
for j in range(1,9):
filelist.insert(k, file+"_"+str(i).zfill(2)+"_"+str(j).zfill(2)+".png")
k=k+1
for i in range(0,num_tiles):
img = scipy.misc.imread(filelist[i])
hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf *hist.max()/ cdf.max()
plt.plot(cdf_normalized, color = 'g')
plt.hist(img.flatten(),256,[0,256], color = 'g')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper left')
cdf_m = np.ma.masked_equal(cdf,0)
cdf_o = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
cdf = np.ma.filled(cdf_o,0).astype('uint8')
img3 = cdf[img]
cv2.imwrite(filelist[i],img3)
image = join(tiles)
image.save('watch-join.png')
filelist. However, guessing from the code I do think you do that, since you seem to be able to read the different images. But my guess is that you forget to update thetilesso at the very end, you justjointhe original, unmodified (thus, not updated) tiles, which of course gives you the original image again. - JohanL