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

Added severe stains texture in PaperFactory. #397

Merged
merged 1 commit into from
Nov 13, 2023
Merged
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
3 changes: 2 additions & 1 deletion augraphy/base/paperfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def generate_random_texture(self, image):
ysize, xsize = image.shape[:2]

# randomize texture type
texture_type = random.choice(["normal", "strange", "rough_stains", "fine_stains", "granular"])
texture_type = random.choice(["normal", "strange", "rough_stains", "fine_stains", "severe_stains", "granular"])

# generate texture
texture = texture_generator(
texture_type=texture_type,
Expand Down
57 changes: 53 additions & 4 deletions augraphy/utilities/texturegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class TextureGenerator:
2. "strange" : Texture generated by an algorithm called "strange pattern".
3. "rough_stains": A rough stains similar texture generated by using FFT.
4. "fine_stains": A fine stains similar texture generated by using FFT.
5. "granular": A light granular texture generated by using FFT.
6. "curvy_edge": Texture with distinct curvy effect on the images edges. Generated by using FFT.
7. "broken_edge": Texture with broken images edges effect. Generated by using FFT.
5. "severe_stains": A severe stains similar texture generated by using FFT.
6. "granular": A light granular texture generated by using FFT.
7. "curvy_edge": Texture with distinct curvy effect on the images edges. Generated by using FFT.
8. "broken_edge": Texture with broken images edges effect. Generated by using FFT.

:param numba_jit: The flag to enable numba jit to speed up the processing.
:type numba_jit: int, optional
Expand Down Expand Up @@ -418,6 +419,43 @@ def generate_fine_stains_texture(self, oxsize, oysize):

return wave_grid_output

def generate_severe_stains_texture(self, oxsize, oysize):
"""Generate severe stains texture using combination of fine and rough stains texture.

:param oxsize: The width of the output texture image.
:type oxsize: int
:param oysize: The height of the output texture image.
:type oysize: int
"""

# fixed internal resolution
ysize, xsize = 500, 500

# merge fine and rough stains
wave_grid_output1 = self.generate_fine_stains_texture(xsize, ysize)
wave_grid_output2 = self.generate_rough_stains_texture(xsize, ysize)
wave_grid_output = wave_grid_output1 * wave_grid_output2

# remove frequency > 50
frequency = 50
wave_grid_output = self.remove_frequency(wave_grid_output, frequency=frequency)

# rescale
wave_grid_output = (wave_grid_output - wave_grid_output.min()) / (
wave_grid_output.max() - wave_grid_output.min()
)

# convert to uint8
wave_grid_output = np.uint8(wave_grid_output * 255)

# median filter to smoothen texture
wave_grid_output = cv2.medianBlur(wave_grid_output, 3)

# resize to output size
wave_grid_output = cv2.resize(wave_grid_output, (oxsize, oysize), interpolation=cv2.INTER_LINEAR)

return wave_grid_output

def generate_FFT_grid(self, xsize, ysize, f_iterations, g_iterations, rresolutions, rA, rf, rp, rkx, rky):
"""Generate random wave grid, process it in FFT and convert it back into spatial domain.

Expand Down Expand Up @@ -750,7 +788,16 @@ def __call__(
# check for image texture generation
if texture_type == "random":
texture_type = random.choice(
["normal", "strange", "rough_stains", "fine_stains", "granular", "curvy_edge", "broken_edge"],
[
"normal",
"strange",
"rough_stains",
"fine_stains",
"severe_stains",
"granular",
"curvy_edge",
"broken_edge",
],
)

if texture_type == "normal":
Expand All @@ -769,6 +816,8 @@ def __call__(
image_texture = self.generate_rough_stains_texture(texture_width, texture_height)
elif texture_type == "fine_stains":
image_texture = self.generate_fine_stains_texture(texture_width, texture_height)
elif texture_type == "severe_stains":
image_texture = self.generate_severe_stains_texture(texture_width, texture_height)
elif texture_type == "granular":
image_texture = self.generate_granular_texture(texture_width, texture_height)
elif texture_type == "curvy_edge":
Expand Down
Loading