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

Generate CSV file to actual image #1

Open
tien-m-duong opened this issue Oct 23, 2024 · 2 comments
Open

Generate CSV file to actual image #1

tien-m-duong opened this issue Oct 23, 2024 · 2 comments

Comments

@tien-m-duong
Copy link

Dear Helen,

Thank you for this interesting work. I was able to the generate a CSV file using GCSbc models. I wonder if there is a way to convert the .csv file to the actual image. I tried to search around but don't see any options. Thank you so much.

Best,
Tien

@helenmand
Copy link
Owner

helenmand commented Oct 24, 2024

Tien,
the GaussianCopulaSynthesizer is used for tabular data. In order to use it in images you must have converted somehow your images to a CSV. For example:

image = Image.open(image_path)

# convert image to numpy array 
image_array = np.array(image)

# flatten into a 1D vector 
flattened_image = image_array.flatten()

Now after using this data, in GaussianCopulaSynthesizer, you can use the generated CSV file to get the images like this:

df = pd.read_csv(generated_csv_path)
image_data = np.array(df.iloc[0]) # for the single image

# reshape the data to its original shape 
image_shape = (564, 564, 3)  # your actual image size
image_array = image_data.reshape(image_shape)

# convert the numpy array back to an image
image = Image.fromarray(image_array.astype(np.uint8))

I hope this helped.

@tien-m-duong
Copy link
Author

tien-m-duong commented Oct 24, 2024

Thank you for your explanation. Just want to confirm my understanding. The problem will run as:

real image .png file(let's say chest X-ray) => convert to numpy array through your first code => run through GaussianCopulaSynthesizer => generated csv file => run through second code to get synthetic chest X-ray images

Please let me know if my understanding is incorrect. Thank you so much

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

2 participants