How to mirror an Image and change its colour


#1

Hi,

I was just wondering if anyone knows how to mirror an image in JUCE, and change it to Black&White.

At the moment I have something like this:

AffineTransform transform4mirroring;
ImageComponent temp;
Image image, mirrorImage;

temp.setImage(image);
temp.setTransform(transform4mirroring.scaled(-1,1));
mirrorImage = temp.getImage();

However, I don’t even know where to begin with the Black&White problem, and when I draw this “mirrorImage” it does not appear (suggesting that maybe this 10 year old solution no longer applies: Mirror images).

So any help would be much appreciated! :slight_smile:


#2

I think the problem is, that you are not really drawing but assingning the image. To draw instead you create a Graphics context and use the draw methods there:

Graphics g (mirrorImage);
AffineTransform transform4mirroring = AffineTransform::scale (-1.0f, 1.0f);
transform4mirroring = transform4mirroring.translated (image.getWidth(), 0.0f);
g.drawImageTransformed (image, transform4mirroring);
// remove color is simple:
mirrorImage.desaturate();

Hope that helps…


#3

Hey!

Thanks for the suggestion, this gets me close.
However, now the mirroring occurs about the x-axis at the centre of the image, like this: [ d | b ], and I’m trying to flip the whole image around, i.e. convert: [ __d __ ] into: [ __b __ ]

After spending some time doing some trail and error with different values, (with the scale ->translated functions), I don’t seem to be getting anywhere.

So if you have any more suggestions, I’d be very grateful :slight_smile:


#4

I’m sorry, I dont quite understand your problem… IMHO flip and mirror is the same, but maybe I’m wrong.
The mirroring was done by adding a negative value to a scale matrix. That maps any X value to it’s negative. Now the image is out of the destination, that’s why I addred the translation by one time the width, so the image is in place again (all as suggested in the thread you linked).
Maybe have a look at AffineTransform class, what you can do with it.

And maybe some math, a helpful arbitrary duckduckgo-hit was: http://www.cs.cornell.edu/Courses/cs4620/2014fa/lectures/08transforms2d.pdf (or browse yourself: https://duckduckgo.com/?q=2d+geometry+transform+lecture&t=ffab&ia=web), I don’t need to write what is already out there…