Skip to content

Commit

Permalink
Cleaned repository (removed old files from the original subject usele…
Browse files Browse the repository at this point in the history
…ss for inpainting).

Translated all my code from french to english
  • Loading branch information
NicolasBizzozzero committed Jun 5, 2019
1 parent c0de9a7 commit 3e557ce
Show file tree
Hide file tree
Showing 25 changed files with 183 additions and 10,295 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Inpainting
[fr] Image inpainting via dictionary learning and sparse representation
Image inpainting via dictionary learning and sparse representation


## Examples
Expand All @@ -14,6 +14,6 @@
* Find a better heuristic for patch approximation order.

## Sources
* Bin Shen and Wei Hu and Zhang, Yimin and Zhang, Yu-Jin, Image Inpainting via Sparse Representation Proceedings of the 2009 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP ’09)
* Bin Shen and Wei Hu and Zhang, Yimin and Zhang, Yu-Jin, Image Inpainting via Sparse Representation Proceedings of the 2009 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP ’09)
* Julien Mairal Sparse coding and Dictionnary Learning for Image Analysis INRIA Visual Recognition and Machine Learning Summer School, 2010
* A. Criminisi, P. Perez, K. Toyama Region Filling and Object Removal by Exemplar-Based Image Inpainting IEEE Transaction on Image Processing (Vol 13-9), 2004
* A. Criminisi, P. Perez, K. Toyama Region Filling and Object Removal by Exemplar-Based Image Inpainting IEEE Transaction on Image Processing (Vol 13-9), 2004
80 changes: 20 additions & 60 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,47 @@
from src.picture_tools.examples import CAMERAMAN, HOUSE, JETPLANE, LAKE, LENA_COLOR_256, LENA_COLOR_512, LENA_GRAY_256, \
LENA_GRAY_512, LIVINGROOM, MANDRIL_COLOR, MANDRIL_GRAY, PEPPERS_COLOR, PEPPERS_GRAY, PIRATE, WALKBRIDGE, \
WOMAN_BLONDE, WOMAN_DARKHAIR, CASTLE, OUTDOOR
from src.picture_tools.codage import Codage
from src.picture_tools.picture import Picture, show_patch, flatten, unflatten, VALUE_MISSING_PIXEL, VALUE_OUT_OF_BOUNDS, get_patch
from src.usps_tools import test_all_usps_1_vs_all, test_all_usps, test_all_usps_sklearn, test_all_usps_1_vs_all_sklearn, \
load_usps_1_vs_all, load_usps
from src.linear.linear_regression import LinearRegression, identite, mse_g, l1, l1_g, l2, l2_g, DescenteDeGradient
from src.picture_tools.colormodel import ColorModel
from src.picture_tools.picture import Picture, VALUE_MISSING_PIXEL, VALUE_OUT_OF_BOUNDS
from src.inpainting import InPainting
from src.common.matplotlib import show_pictures

import matplotlib.pyplot as plt
import numpy as np
from src.picture_tools.examples import CAMERAMAN, HOUSE, JETPLANE, LAKE, LENA_COLOR_256, LENA_COLOR_512,\
LENA_GRAY_256, LENA_GRAY_512, LIVINGROOM, MANDRIL_COLOR, MANDRIL_GRAY, PEPPERS_COLOR, PEPPERS_GRAY, PIRATE,\
WALKBRIDGE, WOMAN_BLONDE, WOMAN_DARKHAIR, CASTLE, OUTDOOR


PATCH_SIZE = 101
STEP = PATCH_SIZE // 4
ALPHA = 0.00001
MAX_ITERATIONS = 100000
TOLERANCE = 0.0001
VALUE_MISSING_PIXEL = VALUE_MISSING_PIXEL
VALUE_OUT_OF_BOUNDS = VALUE_OUT_OF_BOUNDS
CODAGE = Codage.RGB
ALPHA = 1e-5
MAX_ITERATIONS = 1e+5
TOLERANCE = 1e-4
COLOR_MODEL = ColorModel.RGB


def main_lena():
# Chargement de l'image
original_picture = Picture(picture_path=LENA_COLOR_512, codage=CODAGE)
# Load picture
original_picture = Picture(picture_path=LENA_COLOR_512, color_model=COLOR_MODEL)

# Ajout du bruit
# Add noise
noisy_picture = original_picture.copy()
noisy_picture.add_noise(0.005)

main_inpainting(original_picture, noisy_picture)


def main_castle():
# Chargement de l'image
original_picture = Picture(picture_path=CASTLE, codage=CODAGE)
# Load picture
original_picture = Picture(picture_path=CASTLE, color_model=COLOR_MODEL)

# Ajout du bruit
noisy_picture = original_picture.copy() # Ajout du bruit
# Add a rectangle of noise
noisy_picture = original_picture.copy()
noisy_picture.add_rectangle(400, 380, 50, 20)

main_inpainting(original_picture, noisy_picture)


def main_outdoor():
# Chargement de l'image
original_picture = Picture(picture_path=OUTDOOR, codage=CODAGE)
# Load picture
original_picture = Picture(picture_path=OUTDOOR, color_model=COLOR_MODEL)

# Ajout du bruit
# Add a rectangle of noise
noisy_picture = original_picture.copy()
noisy_picture.add_rectangle(288, 497, 190, 80)

Expand All @@ -64,44 +56,12 @@ def main_inpainting(original_picture, noisy_picture, patch_size=PATCH_SIZE, step
value_out_of_bounds=value_out_of_bounds)
inpainted_picture = inpainting.inpaint(noisy_picture)

# Affichage des résultats
# Show resulting pictures
show_pictures(pictures=[original_picture._get_showable_picture(), noisy_picture._get_showable_picture(),
inpainted_picture._get_showable_picture()],
titles=["Original picture", "Noisy picture", "InPainted picture"],
save_path=save_path)


def main_all_vs_all():
print("TEST ALL VS ALL")
test_all_usps(classifieur=LinearRegression,
loss_g=mse_g,
type_descente=DescenteDeGradient.BATCH,
alpha=0)
for loss_g in (l2_g, l1_g):
for alpha in (0, 0.25, 0.5, 0.75, 1):
print(loss_g.__name__, "alpha=" + str(alpha))
test_all_usps(classifieur=LinearRegression,
loss_g=loss_g,
type_descente=DescenteDeGradient.BATCH,
alpha=alpha)

test_all_usps_sklearn(alpha=1.0)


def main_1_vs_all():
print("TEST 1 VS ALL")
test_all_usps_1_vs_all(classifieur=LinearRegression,
loss_g=mse_g,
type_descente=DescenteDeGradient.BATCH,
alpha=0)
for loss_g in (l1_g, l2_g):
for alpha in (0, 0.25, 0.5, 0.75, 1):
print(loss_g.__name__, "alpha=" + str(alpha))
test_all_usps_1_vs_all(classifieur=LinearRegression,
loss_g=loss_g,
type_descente=DescenteDeGradient.BATCH,
alpha=alpha)


if __name__ == "__main__":
main_outdoor()
Loading

0 comments on commit 3e557ce

Please sign in to comment.