Open protector131090 opened 1 month ago
The main issue seems to be the limited available options for the initial latent (just 4 different gradients) when instead you could be using an arbitrary image/mask for the initial latent.
I have locally implemented some basic functionality to either provide an image file for the initial latent or to generate an initial latent that just covers the foreground object in light. It's a little rough so I haven't made a PR yet, but I'm happy to share the code (see attachment; anyone may feel free to modify and/or distribute whatever I changed without attribution).
If you use Lighting Preference 'Image', the program expects a PNG file named custom_latent.png
in the project folder (next to gradio_demo.py
). The Lighting Preference 'Foreground' creates a mask that only covers the foreground of the image (except pixels that are very close to rgb 7f7f7f).
I also made it so it writes the latest latent image into latent.png
so you can take a look at it and modify it in an image editor if necessary.
Please provide us with your custom_latent.png image?
Please provide us with your custom_latent.png image?
The point is that you can supply your own custom_latent.png
. Every image is different and there isn't one single initial latent that works best for everything.
I attached some examples below so you can get an idea of what it might look like:
Here's a code that randomly picks up images with any name stored in a folder named random-images to apply the latent:
elif bg_source == BGSource.IMAGE_FILE_RANDOM:
folder_path = './random-images'
image_files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
if not image_files:
raise ValueError('No images found in the folder!')
random_image_path = os.path.join(folder_path, random.choice(image_files))
input_bg = np.array(Image.open(random_image_path).resize((image_width, image_height))).astype(np.uint8)
Do note, the code provided "V1sionVerse" will not handle RGBA. More modifications must be made to resize_and_center_crop and resize_without_crop; mainly:
pil_image = Image.fromarray(image)
if pil_image.mode == 'RGBA':
pil_image = pil_image.convert('RGB')
original_width, original_height = pil_image.size
This should allow you to use any platform, or application to create your latent image and regardless of whether your image has an alpha channel, it will work.
Do note, the code provided "V1sionVerse" will not handle RGBA. More modifications must be made to resize_and_center_crop and resize_without_crop
Thanks, I did run into that issue myself and ended up having to convert the image to 24-bit RGB manually. I'm glad I won't have to do that anymore :)
thank you @V1sionVerse and @iloveoss , more idea had applied, It's very beautiful and there's a lot more imagination to work with.
thank you @V1sionVerse and @iloveoss , more idea had applied, It's very beautiful and there's a lot more imagination to work with.
This is just a small update with the image picker. My previous code picks any random image from the random-images folder. But with this new update, it will make sure not to pick the same image again untill all available image options are exhausted.
1st:
class ImagePicker:
def __init__(self, folder_path):
self.folder_path = folder_path
self.image_files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
if not self.image_files:
raise ValueError('No images found in the folder!')
self.used_images = []
self.shuffle_images()
def shuffle_images(self):
self.used_images = self.image_files[:]
random.shuffle(self.used_images)
def get_next_image(self):
if not self.used_images:
self.shuffle_images()
return self.used_images.pop()
2nd
elif bg_source == BGSource.IMAGE_FILE_RANDOM:
folder_path = './random-images' # Path to the folder containing random images
image_files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
if not image_files:
raise ValueError('No images found in the folder!')
random_image_path = os.path.join(folder_path, random.choice(image_files))
input_bg = np.array(Image.open(random_image_path).resize((image_width, image_height))).astype(np.uint8)
@iloveoss :Is there an updated corrected file available for download? thank you!
@iloveoss :Is there an updated corrected file available for download? thank you!
ok, thank, I've corrected it because I was very sleepy last night, corrected it wrong, slept through the night, and now I'm energized.
Every image i make is very dramatic low-key image. I never seen normal bright or flash photography made. is it possible?! prompts dont help...