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

How do you create the figures in your research paper? #24

Open
GoldenFishes opened this issue Oct 22, 2023 · 12 comments
Open

How do you create the figures in your research paper? #24

GoldenFishes opened this issue Oct 22, 2023 · 12 comments

Comments

@GoldenFishes
Copy link

Could you please show me how figures 2 and 3 in the paper were created? Such as,the figure of “The denoising process(figure 2)” and “Relative log amplitudes of Fourier for diffusion inter-mediate steps(figure 3)”

@GoldenFishes
Copy link
Author

Never mind,I got it.

@ewrfcas
Copy link

ewrfcas commented Nov 7, 2023

Could you please show me how figures 2 and 3 in the paper were created? Such as,the figure of “The denoising process(figure 2)” and “Relative log amplitudes of Fourier for diffusion inter-mediate steps(figure 3)”

I have the same question. How do you draw these figures?

@GoldenFishes
Copy link
Author

Could you please show me how figures 2 and 3 in the paper were created? Such as,the figure of “The denoising process(figure 2)” and “Relative log amplitudes of Fourier for diffusion inter-mediate steps(figure 3)”

I have the same question. How do you draw these figures?

Well, since you've asked, I'd like to know your research direction first.

@ewrfcas
Copy link

ewrfcas commented Nov 7, 2023

Could you please show me how figures 2 and 3 in the paper were created? Such as,the figure of “The denoising process(figure 2)” and “Relative log amplitudes of Fourier for diffusion inter-mediate steps(figure 3)”

I have the same question. How do you draw these figures?

Well, since you've asked, I'd like to know your research direction first.

Now, I am interested in image synthesis.
I just know the way to draw the figure of amplitude/sampling frequency as follows:
image

@GoldenFishes
Copy link
Author

Now, I am interested in image synthesis. I just know the way to draw the figure of amplitude/sampling frequency as follows: image

So, you're not involved in research related to diffusion models?

@GoldenFishes
Copy link
Author

Could you please show me how figures 2 and 3 in the paper were created? Such as,the figure of “The denoising process(figure 2)” and “Relative log amplitudes of Fourier for diffusion inter-mediate steps(figure 3)”

I have the same question. How do you draw these figures?

import cv2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap

def calculate_relative_log_frequency(image):
# Perform Fourier transform
fourier_transform = np.fft.fft2(image)
# Calculate the amplitude of the Fourier transform
amplitude = np.abs(fourier_transform)
# Calculate the relative log frequency
relative_log_frequency = np.log(amplitude + 1) - np.log(amplitude[0, 0] + 1) # Relative to the log frequency at 0 point
# Get the width of the image
image_width = image.shape[1]
# Calculate frequency values on the axis
frequency_values = np.fft.fftfreq(image_width)

# Keep only the part in the range 0.0 to 1.0
valid_indices = (frequency_values >= 0.0) & (frequency_values <= 1.0 / np.pi)
frequency_values = frequency_values[valid_indices]
relative_log_frequency = relative_log_frequency[:, valid_indices]

# Reduce data points to reduce oscillation
# Here, we add a step to take every 4th value
frequency_values = frequency_values[::4]
relative_log_frequency = relative_log_frequency[:, ::4]

# Rescale frequency values to the range 0.0 to 1.0
frequency_values = (frequency_values - min(frequency_values)) / (max(frequency_values) - min(frequency_values))
return relative_log_frequency[0], frequency_values

def plot_multiple_relative_log_frequencies(image_filenames, alpha=0.8):
plt.figure(figsize=(12, 6))
cmap = get_cmap('Blues')

new_labels = ["step1", "step100", "step200",
              "step300", "step400", "step500",
              "step600", "step700", "step800",
              "step900", "step1000"]

for i, filename in enumerate(image_filenames):
    image = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
    relative_log_frequency, frequency_values = calculate_relative_log_frequency(image)

    k = i / len(image_filenames)
    color = cmap(k + 0.2)

    # Use the new labels
    label = new_labels[i]

    # Adjust the alpha parameter to control the transparency of the curve
    plt.plot(frequency_values, relative_log_frequency, color=color, label=label, linewidth=2.5, alpha=alpha)

plt.xlabel('Frequency')
plt.ylabel('Relative Log Amplitude')
plt.xlim(0.0, 1.0)
plt.grid(True)
plt.legend()

# Modify x-axis labels
x_ticks = np.linspace(0, 1, 6)
x_tick_labels = [f'{x:.1f}π' for x in x_ticks]
plt.xticks(x_ticks, x_tick_labels)

plt.show()

Example usage

image_filenames = ["0-eps1.0.png", "0-eps0.9.png", "0-eps0.8.png",
"0-eps0.7.png", "0-eps0.6.png", "0-eps0.5.png",
"0-eps0.4.png", "0-eps0.3.png", "0-eps0.2.png",
"0-eps0.1.png", "0-eps0.0.png"]

plot_multiple_relative_log_frequencies(image_filenames)

@GoldenFishes
Copy link
Author

I apologize for the formatting issue in the code. I hope it can help you.

@ewrfcas
Copy link

ewrfcas commented Nov 7, 2023

I apologize for the formatting issue in the code. I hope it can help you.

Thanks for your reply!

@FatLong666
Copy link

I apologize for the formatting issue in the code. I hope it can help you.

The code you apply above is about how to draw the Fig3? Do you konw how to draw the Fig2? Hope you can help me.

@GoldenFishes
Copy link
Author

The code you apply above is about how to draw the Fig3? Do you konw how to draw the Fig2? Hope you can help me.

I can do Fig2 in other model such as U-ViT in UniDiffuser, I haven't try it in StableDiffusion U-Net.

@FatLong666
Copy link

The code you apply above is about how to draw the Fig3? Do you konw how to draw the Fig2? Hope you can help me.

I can do Fig2 in other model such as U-ViT in UniDiffuser, I haven't try it in StableDiffusion U-Net.

Could you share the code with me about how to draw the Fig2 in U-ViT? Is it use the low or high filters to achieve it?

@GoldenFishes
Copy link
Author

Could you share the code with me about how to draw the Fig2 in U-ViT? Is it use the low or high filters to achieve it?

The method for generating intermediate results in the denoising process can be found in my open-source code. Once you obtain these intermediate results, separating the high and low frequencies becomes much easier.
GoldenFishes/FreeV#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants