from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
The raw code for this IPython notebook is by default hidden for easier reading.
To toggle on/off the raw code, click <a href="javascript:code_toggle()">here</a>.''')
import matplotlib.pyplot as plt
%matplotlib inline
In this project, we are trying to use image processing technique to automatically produce a color image with as few visual artifacts as possible. Here's the implementation we did:
Issues I encountered and the way I solved the issues:
The runtime at first is pretty long for pyramid algorithm. I found two ways to solve the issue:
For low-resolution images (jpg images), we implement exhaustic search to align the three color channels (r,g,b) and produce a color image. Algorithm:
Here's the result for jpg images, the displacements are indicated in the bracket:
img1=plt.imread('out_cathedral.jpg')
img2=plt.imread('out_monastery.jpg')
img3=plt.imread('out_obolsk.jpg')
f=plt.figure(figsize=(20, 20))
ax1=f.add_subplot(1,3,1)
ax2=f.add_subplot(1,3,2)
ax3=f.add_subplot(1,3,3)
ax1.imshow(img1)
ax2.imshow(img2)
ax3.imshow(img3)
ax1.set_axis_off()
ax2.set_axis_off()
ax3.set_axis_off()
ax1.set_title('cathedral.jpg, g[5,2], r[12,3]')
ax2.set_title('monastery.jpg, g[-3,2], r[3,2]')
ax3.set_title('tobolsk.jpg, g[3,3], r[6,3]')
plt.show()
For high-resolution images (tif images), we implement pyramid search by recursively calling the exhaustic search algorithm to align the three color channels (r,g,b) and produce a color image. Algorithm:
Here's the result for tif images, the displacements are indicated in the bracket:
img1=plt.imread('out_emir.jpg')
img2=plt.imread('out_harvesters.jpg')
img3=plt.imread('out_con.jpg')
img4=plt.imread('out_lady.jpg')
img5=plt.imread('out_melons.jpg')
img6=plt.imread('out_onion_church.jpg')
img7=plt.imread('out_self_portra.jpg')
img8=plt.imread('out_hree_generations.jpg')
img9=plt.imread('out_rain.jpg')
img10=plt.imread('out_village.jpg')
img11=plt.imread('out_worksho.jpg')
f=plt.figure(figsize=(20, 20))
ax1=f.add_subplot(4,3,1)
ax2=f.add_subplot(4,3,2)
ax3=f.add_subplot(4,3,3)
ax4=f.add_subplot(4,3,4)
ax5=f.add_subplot(4,3,5)
ax6=f.add_subplot(4,3,6)
ax7=f.add_subplot(4,3,7)
ax8=f.add_subplot(4,3,8)
ax9=f.add_subplot(4,3,9)
ax10=f.add_subplot(4,3,10)
ax11=f.add_subplot(4,3,11)
ax1.imshow(img1)
ax2.imshow(img2)
ax3.imshow(img3)
ax4.imshow(img4)
ax5.imshow(img5)
ax6.imshow(img6)
ax7.imshow(img7)
ax8.imshow(img8)
ax9.imshow(img9)
ax10.imshow(img10)
ax11.imshow(img11)
ax1.set_axis_off()
ax2.set_axis_off()
ax3.set_axis_off()
ax4.set_axis_off()
ax5.set_axis_off()
ax6.set_axis_off()
ax7.set_axis_off()
ax8.set_axis_off()
ax9.set_axis_off()
ax10.set_axis_off()
ax11.set_axis_off()
ax1.set_title('emir.tif, g[49,24], r[103,57]')
ax2.set_title('harvester.tif, g[59,16], r[124,13]')
ax3.set_title('icon.tif, g[41,17], r[90,23]')
ax4.set_title('lady.tif, g[56,8], r[116,11]')
ax5.set_title('melons.tif, g[82,11], r[178,13]')
ax6.set_title('onion_church.tif, g[51,27], r[108,36]')
ax7.set_title('self_portrait.tif, g[79,29], r[176,36]')
ax8.set_title('three_generations.tif, g[53,14], r[112,11]')
ax9.set_title('train.tif, g[42,6], r[87,32]')
ax10.set_title('village.tif, g[65,12], r[138,22]')
ax11.set_title('workshop.tif, g[53,0], r[105,-12]')
plt.show()
img1=plt.imread('out_00082a.jpg')
img2=plt.imread('out_00162a.jpg')
img3=plt.imread('out_00163v.jpg')
img4=plt.imread('out_00170v.jpg')
f=plt.figure(figsize=(20, 20))
ax1=f.add_subplot(1,4,1)
ax2=f.add_subplot(1,4,2)
ax3=f.add_subplot(1,4,3)
ax4=f.add_subplot(1,4,4)
ax1.imshow(img1)
ax2.imshow(img2)
ax3.imshow(img3)
ax4.imshow(img4)
ax1.set_axis_off()
ax2.set_axis_off()
ax3.set_axis_off()
ax4.set_axis_off()
ax1.set_title('tif 1, g[32,4], r[79,7]')
ax2.set_title('tif 2, g[35,3], r[98,4]')
ax3.set_title('jpg 1, g[-3,1], r[-4,1]')
ax4.set_title('jpg 2, g[4,-2], r[-6,-6]')
plt.show()
We implement automatic cropping to remove white, black or other color borders. The algorithm is:
img1=plt.imread('out_con.jpg')
img2=plt.imread('crop_out_con.jpg')
f=plt.figure(figsize=(20, 20))
ax1=f.add_subplot(1,2,1)
ax2=f.add_subplot(1,2,2)
ax1.imshow(img1)
ax2.imshow(img2)
ax1.set_axis_off()
ax2.set_axis_off()
ax1.set_title('icon.jpg, raw image')
ax2.set_title('crop_icon.jpg, cropped image')
plt.show()