augraphy
augraphy copied to clipboard
Add new augmentation - Leaky Ink Effect
I came across several images with effect looks like ink is leaking into the paper, and usually the effect is at the borders or edges of paper. Probably we can add this effect too?
Example:
A more severe ink leaking example:
Please suggest a better name for this augmentation too.
This effect appears all the time, especially in scans of faxes of old documents.
I think this can probably be a part of BadPhotoCopy, but we can start by developing it separately. For now, we could use BadFax for the name, to fit BadPhotoCopy.
In all of these images, we can see a white border around the text inside the large dark regions. We can probably do something like the following to replicate this effect:
- randomly select a region to add this effect to,
- use the Sobel filter to get edges in this region (A),
- add noise around the edges in this region to "enlarge" the edge mask (B),
- subtract the edge mask from the region, removing the text
- apply very heavy noise in the region
- add the negative of (B) back to the region, creating a white area around the text,
- add (A) back to the image, printing black text over the white region from part 6
Right, this should be feasible with current badphotocopy augmentation. Probably we just need to adjust the code a bit to produce a different noise pattern.
Can we produce a copy of this with BadPhotoCopy and/or the upcoming Faxify?
Can we produce a copy of this with BadPhotoCopy and/or the upcoming Faxify?
Not with Faxify, but it is possible with Badphotocopy, I will work on a different hash type in BadPhotoCopy to produce this effect after my next update on the Faxify.
Does the new Faxify update allow this kind of effect?
Does the new Faxify update allow this kind of effect?
Nope, faxify is creating something like monochrome (black & white) and halftone. We have something similar but not exactly with badphotocopy (hash type = 1). For example:
We are still not able to create a consistent wavy pattern yet, so is this really needed? If yes i will look further on how to reproduce it.
I think we could use the following algorithm to reproduce this effect with the wave pattern:
- randomly choose 2 edges of the page (must be different edges),
edge1
andedge2
- randomly choose a point on each of the edges, let's call them
p_start
andp_end
- randomly pick a number
n
, maybe in the interval (3,7) to start - randomly pick
n
points in the image,p1
,p2
, ...,pn
- use the Chaikin algorithm to create a contour connecting
p_start
,p1
, ...,pn
,p_end
- randomly pick one side of this contour
- use the contour,
edge1
, andedge2
as the boundary of a region of the page - get the mask corresponding to this region, with all transparent pixels in the other part of the mask
- apply
BadPhotoCopy
to this mask - layer the mask back onto the original document
Good idea, i think we can try this out.
Good idea, i think we can try this out.
I tried but looks like i'm getting a straight line with chaikin
and smooth
, is there any example of chaikin
usage? Anyway, right now i'm trying to use a sine wave curve to reproduce a similar effect, i will push again when it is done.
...looks like i'm getting a straight line with
chaikin
andsmooth
, is there any example ofchaikin
usage?
The Strikethrough augmentation uses chaikin via the call to smooth.
This may be oversimplifying it, but I think the idea is first to create a sequence of random points across the page in such a way that they could be connected and smoothed. The smoothed line would connect any one side of the page to any of the 4 sides (including the starting side).
Then, complete the creation of an enclosing shape using from 1 to 5 straight lines, depending on which direction was chosen and the location of the start/stop points. The straight lines will either join to a corner or the start/stop points.
The enclosing shape would then serve as the mask for partially applying the bad copy effect.
^ This is exactly what I meant
I tried with this approach, the output looks jagged, it wouldn't look natural in way:
The code to reproduce it:
img = np.zeros((800,800),dtype='uint8')
point_x = [0, 100, 200, 250, 450, 500]
point_y = [100, 450, 50, 300, 50, 300]
for i in (range(len(point_x)-1)):
point1 = [point_x[i], point_y[i]]
point2 = [point_x[i+1], point_y[i+1]]
points = chaikin([point1,point2])
smooth_points = smooth(points,5)
for x,y in smooth_points:
img[int(y),int(x)] = 255
plt.figure()
plt.scatter(point_x, point_y)
plt.imshow(img)
The output:
To smooth it, i tried with some curve fitting:
The code to reproduce it:
img = np.zeros((800,800),dtype='uint8')
ysize, xsize = img.shape[:2]
point_x = [0, 100, 200, 250, 450, 500]
point_y = [100, 450, 50, 300, 50, 300]
for i in (range(len(point_x)-3)):
all_x = [point_x[i], point_x[i+1], point_x[i+2], point_x[i+3]]
all_y = [point_y[i], point_y[i+1], point_y[i+2], point_y[i+3]]
xnew = np.linspace(min(all_x), max(all_x), 500).astype('int')
tck = splrep(all_x, all_y)
ynew = splev(xnew, tck)
for x,y in zip(xnew, ynew):
img[min(int(y),ysize-1),min(int(x),xsize-1)] = 255
plt.figure()
plt.scatter(point_x, point_y)
plt.imshow(img)
The output:
We can further mask the overlapped area:
So i think we need an additional curve fitting process to create a more natural effect.
Ok, so there is a logical error here while applying the chaikins algorithm. By writing the smooth function inside the for i in (range(len(point_x)-3)):
you are basically smoothing each pair of points independently (which is a line). However, the algorithm needs a list of more than 2 points to generate a smoothing effect.
Correct way would be
img = np.zeros((800, 800), dtype='uint8')
point_x = [0, 100, 200, 250, 450, 500]
point_y = [100, 450, 50, 300, 50, 300]
points=[]
for i in (range(len(point_x) )):
p = [point_x[i], point_y[i]]
points.append(p)
print(points)
smooth_points = smooth(points, 10)
for x, y in smooth_points:
img[int(y), int(x)] = 255
plt.figure()
# plt.scatter(point_x, point_y)
plt.imshow(img,cmap="gray")
plt.show()
Ok, so there is a logical error here while applying the chaikins algorithm. By writing the smooth function inside the
for i in (range(len(point_x)-3)):
you are basically smoothing each pair of points independently (which is a line). However, the algorithm needs a list of more than 2 points to generate a smoothing effect.
Ah, thanks, this should be suitable to generate the wave pattern and replace the current curve fitting workflow in Badphotocopy
. We may either mask the top or bottom part of wave too:
Also it would be nice if we can at least include some comments or notes in those functions, so that the other user know the correct way to use it too.
This looks great, but I think we still want the curve to end at one of the edges so it looks more natural.
I also agree that we always need more comments, and we should have a markdown file in the docs
folder for every augmentation.
Also it would be nice if we can at least include some comments or notes in those functions, so that the other user know the correct way to use it too.
Sure, I will do this in my next PR.
These can now be reproduced with BadPhotoCopy, right?
These can now be reproduced with BadPhotoCopy, right?
Not exactly, we can reproduce a similar effect, but those noise look sparser (lighter). I will include another update to adjust the noise density later.
@kwcckw I believe we have reproduced this effect in one of the archetypes; however, I don't know that we have generalized the generation of this effect in a parameterized and natural way within the library. Can you confirm the current state of this feature implementation?
@kwcckw I believe we have reproduced this effect in one of the archetypes; however, I don't know that we have generalized the generation of this effect in a parameterized and natural way within the library. Can you confirm the current state of this feature implementation?
This is now in BadPhotoCopy
, by enabling wave_pattern
, we should see this effect.