Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs on file integration and some code errors #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Watermarking .ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.8.2"
}
},
"nbformat": 4,
Expand Down
Binary file removed final/fotolia_137840668.jpg
Binary file not shown.
Binary file removed final/fotolia_168667147.jpg
Binary file not shown.
Binary file removed final/fotolia_168667186.jpg
Binary file not shown.
Binary file removed final/fotolia_168667261.jpg
Binary file not shown.
Binary file removed final/fotolia_168667468.jpg
Binary file not shown.
Binary file removed final/fotolia_168667490.jpg
Binary file not shown.
Binary file removed final/fotolia_168668046.jpg
Binary file not shown.
Binary file removed final/fotolia_168668148.jpg
Binary file not shown.
Binary file removed final/fotolia_168668150.jpg
Binary file not shown.
Binary file removed final/fotolia_168668190.jpg
Binary file not shown.
Binary file removed final/fotolia_75353029.jpg
Binary file not shown.
38 changes: 22 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,50 @@

# est = poisson_reconstruct(gx, gy, np.zeros(gx.shape)[:,:,0])
cropped_gx, cropped_gy = crop_watermark(gx, gy)
W_m = poisson_reconstruct(cropped_gx, cropped_gy)

# random photo
img = cv2.imread('images/fotolia_processed/fotolia_137840645.jpg')
img = cv2.imread('images/fotolia_processed/fotolia_137840668.jpg')
im, start, end = watermark_detector(img, cropped_gx, cropped_gy)

# # Save result of watermark detection
# plt.subplot(1, 2, 1)
# plt.imshow(img)
# plt.subplot(1, 2, 2)
# plt.imshow(im)
# plt.show()
# plt.savefig('images/results/watermark_detect_result.png')
# We are done with watermark estimation

# W_m is the cropped watermark
W_m = poisson_reconstruct(cropped_gx, cropped_gy)

# Get the number of images in the folder
num_images = len(gxlist)

J, img_paths = get_cropped_images('images/fotolia_processed', num_images, start, end, cropped_gx.shape)
J, img_paths = get_cropped_images(
'images/fotolia_processed', num_images, start, end, cropped_gx.shape)

# get a random subset of J
idx = [389, 144, 147, 468, 423, 92, 3, 354, 196, 53, 470, 445, 314, 349, 105, 366, 56, 168, 351, 15, 465, 368, 90, 96, 202, 54, 295, 137, 17, 79, 214, 413, 454, 305, 187, 4, 458, 330, 290, 73, 220, 118, 125, 180, 247, 243, 257, 194, 117, 320, 104, 252, 87, 95, 228, 324, 271, 398, 334, 148, 425, 190, 78, 151, 34, 310, 122, 376, 102, 260]
idx = idx[:25]
# Wm = (255*PlotImage(W_m))
Wm = W_m - W_m.min()

# get threshold of W_m for alpha matte estimate
alph_est = estimate_normalized_alpha(J, Wm)
Wm = W_m - W_m.min()

# estimate alpha matte
alph_est = estimate_normalized_alpha(J, Wm, num_images=len(J))
alph = np.stack([alph_est, alph_est, alph_est], axis=2)
C, est_Ik = estimate_blend_factor(J, Wm, alph)

alpha = alph.copy()
for i in xrange(3):
alpha[:,:,i] = C[i]*alpha[:,:,i]
for i in range(3):
alpha[:, :, i] = C[i]*alpha[:, :, i]

Wm = Wm + alpha*est_Ik

W = Wm.copy()
for i in xrange(3):
W[:,:,i]/=C[i]
for i in range(3):
W[:, :, i] /= C[i]

Jt = J[:25]

# now we have the values of alpha, Wm, J
# Solve for all images
Wk, Ik, W, alpha1 = solve_images(Jt, W_m, alpha, W)
# W_m_threshold = (255*PlotImage(np.average(W_m, axis=2))).astype(np.uint8)
# ret, thr = cv2.threshold(W_m_threshold, 127, 255, cv2.THRESH_BINARY)

8 changes: 4 additions & 4 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from estimate_watermark import *
from preprocess import *
from image_crawler import *
from watermark_reconstruct import *
from .estimate_watermark import *
from .preprocess import *
from .image_crawler import *
from .watermark_reconstruct import *
Loading