Horizontal Flip of Image

Only half my image gets flipped

Page 1 of 1

2 Replies - 8769 Views - Last Post: 17 February 2009 - 04:39 PM Rate Topic: -----

#1 En3myx0fxG0d  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 17-February 09

Horizontal Flip of Image

Post icon  Posted 17 February 2009 - 04:19 PM

So I'm trying to write a class that acts as a filter for an image. its role is to take an image and flip it so that it looks like your looking in a mirror. so far all i've got is a filter that flips half the image and leaves the rest alone can anyone help me out?

public void apply(OFImage image)
	{  
		int height = image.getHeight();
		int width = image.getWidth();
		for(int x = 0; x < width; x++)
		{
			for(int y = 0; y < height; y++) {
				image.setPixel(x, y, image.getPixel(width-x-1,y));
			}
		}


Thanks to anyone who can give me a hand. Yea i know this destroys the original image but thats fine.

Is This A Good Question/Topic? 0
  • +

Replies To: Horizontal Flip of Image

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1105
  • View blog
  • Posts: 6,918
  • Joined: 07-September 06

Re: Horizontal Flip of Image

Posted 17 February 2009 - 04:32 PM

The problem with this is that it is flipping the image and writing to the same image as it is being flipped. This causes it to look like it is 2 of the same halves of the image.

You will have to create a copy of the image if you want to get the full thing flipped.

Maybe try this:

public void apply(OFImage image)
	{  
		int height = image.getHeight();
		int width = image.getWidth();
		OFImage copy = image;
		for(int x = 0; x < width; x++)
		{
			for(int y = 0; y < height; y++) {
				image.setPixel(x, y, copy.getPixel(width-x-1,y));
			}
		}


NOTE - I haven't tried it, so it may not work out correctly without having some more editing done.

HTH
Was This Post Helpful? 0
  • +
  • -

#3 En3myx0fxG0d  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 17-February 09

Re: Horizontal Flip of Image

Posted 17 February 2009 - 04:39 PM

View PostBetaWar, on 17 Feb, 2009 - 03:32 PM, said:

The problem with this is that it is flipping the image and writing to the same image as it is being flipped. This causes it to look like it is 2 of the same halves of the image.

You will have to create a copy of the image if you want to get the full thing flipped.

Maybe try this:

public void apply(OFImage image)
	{  
		int height = image.getHeight();
		int width = image.getWidth();
		OFImage copy = image;
		for(int x = 0; x < width; x++)
		{
			for(int y = 0; y < height; y++) {
				image.setPixel(x, y, copy.getPixel(width-x-1,y));
			}
		}


NOTE - I haven't tried it, so it may not work out correctly without having some more editing done.

HTH

Same issue happens. one thing I noticed is the image.setPixel..... when the first x is set to width-x-1 the first half of the picture gets flipped. if the second x in the getPixel call is changed to width-x-1 then the second half of the image is flipped. both set to width-x-1 cancels each other out. is their maybe a problem with my counter in the for loop?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1