NVlabs / stylegan3

Official PyTorch implementation of StyleGAN3
Other
6.38k stars 1.12k forks source link

how to add horizontal mirror left/right in visualizer.py? #137

Open nicolai256 opened 2 years ago

nicolai256 commented 2 years ago

how to add horizontal mirror left/right in visualizer.py? i'm trying to add an option for mirroring horzontally both left and right in visualizer.py, just a button. anyone who knows how to add this? i'm using stylegan3-fun and I see they already added a lot of options so it must be possible. and also a zoom out/in dragger but one that doesn't morph the image.. thanks

PDillis commented 2 years ago

Hey, the fork you mention is mine, and the buttons for horizontal and vertical mirroring are already added in the GUI, theyr'e at the bottom (you can better see it being used at the end of this video).

nicolai256 commented 2 years ago

Hey, the fork you mention is mine, and the buttons for horizontal and vertical mirroring are already added in the GUI, theyr'e at the bottom (you can better see it being used at the end of this video).

hi, thanks for answering. what I mean is mirror image like this [https://www.google.com/url?sa=i&url=https%3A%2F%2Fpetapixel.com%2F2013%2F02%2F04%2Fstrange-floating-formations-created-by-mirroring-photos-of-trees%2F&psig=AOvVaw3Ef7SBfG1WsgSlKFDPBjYO&ust=1647902279459000&source=images&cd=vfe&ved=0CAsQjRxqFwoTCLjNy8Tg1fYCFQAAAAAdAAAAABAD] the mirror option in your GUI is actually more a flip but the gui is already super great, thanks for creating that!!

PDillis commented 2 years ago

Ah, I see, in StyleGAN we've referred to mirror as the horizontal or vertical flipping for augmenting the training dataset, so I just kept the nomenclature. The mirroring you mention is a bit more than what I've envisioned of doing, but I think it is doable: all of these buttons/sliders/effects are done via affine transformations, so using Benjamin Botto's excellent Medium article, we should achieve this by translating, reflecting, then translating back again one half of the image w.r.t the y axis (for a vertical mirror), then replacing the result in the other half. A more powerful thing to do is to decide where this mirror is, but again, I haven't really envisioned this so I haven't planned for it. If I do it, I can't really ensure you a specific timeline, so if you are able to implement it, I'd be happy to accept a pull request!

nicolai256 commented 2 years ago

Ah, I see, in StyleGAN we've referred to mirror as the horizontal or vertical flipping for augmenting the training dataset, so I just kept the nomenclature. The mirroring you mention is a bit more than what I've envisioned of doing, but I think it is doable: all of these buttons/sliders/effects are done via affine transformations, so using Benjamin Botto's excellent Medium article, we should achieve this by translating, reflecting, then translating back again one half of the image w.r.t the y axis (for a vertical mirror), then replacing the result in the other half. A more powerful thing to do is to decide where this mirror is, but again, I haven't really envisioned this so I haven't planned for it. If I do it, I can't really ensure you a specific timeline, so if you are able to implement it, I'd be happy to accept a pull request!

Thanks for the info, do you know which files need to be altered in the repo to do it?

I'll try to screw around with it and see what it gives me, I'll let you know if I succeed or not.

PDillis commented 2 years ago

To add the button to mirror, you would need to do it in the EquivarianceWidget. You'd also need to add the respective inverse matrix for the mirroring in the make_affine_transform function (make sure the default is the identity matrix). Those are the main ones, but maybe there are other things to change as well. Let me know how it goes!

nicolai256 commented 2 years ago

To add the button to mirror, you would need to do it in the EquivarianceWidget. You'd also need to add the respective inverse matrix for the mirroring in the make_affine_transform function (make sure the default is the identity matrix). Those are the main ones, but maybe there are other things to change as well. Let me know how it goes!

I tried but the visualizer seems to crash, thanks anyways :)

nicolai256 commented 2 years ago

https://legacy.imagemagick.org/Usage/distorts/#distort_viewport