We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › resize hard edges
Page Index Toggle Pages: 1
resize hard edges (Read 780 times)
resize hard edges
Jun 1st, 2009, 2:52pm
 
How can I resize an image so that it preserves hard edges similar to nearest neighbor mode in photoshop?

I have a 365x365 image that consists of 1 pixel vertical lines and I am using imageName.resize(730,730); to try and double it, making the vertical lines 2 pixels wide.

The resize command works but it seems to be doing a bicubic method or something because the lines end up blurring together when I double the size of the image.

Thanks
Re: resize hard edges
Reply #1 - Jun 1st, 2009, 4:31pm
 
i just tested it but i get exactly the effect you want.
Re: resize hard edges
Reply #2 - Jun 2nd, 2009, 1:24am
 
Perhaps you have the smooth() option activated? Might also depend on the graphics mode you chose.
Re: resize hard edges
Reply #3 - Jun 2nd, 2009, 6:53pm
 
I do not have smooth activated as far as I can tell and I just went ahead and added noSmooth() into a bunch of different places in my program (redundantly in case smooth was being set somewhere I wasnt aware of).  It still appears to be smoothing the resize.

I tried it in both standard mode and P2D.  Could this be because I am on a mac (macs seem to like to smooth everything)?  Does anyone have any other ideas?

A little more background: my program is running a second applet and frame and the image is being displayed on the secondary one (it is fixed location on a second monitor as per the recent thread).

here is one of the images before resizing and a small clip from a screenshot of the resized image (that is clearly not square on the edges)  I am not allowed to post links yet but here they are, the first one is clearly smoothed
img193.imageshack.us/my.php?image=smooth.png
img200.imageshack.us/my.php?image=406794.png
Re: resize hard edges
Reply #4 - Jun 2nd, 2009, 7:16pm
 
also, for reference, I have all of my code here: pastebin.com/m2f304e2f

It is messy since I left in my different attempts at getting non-smoothing to work (commented out lines that do different things and the excess noSmooth()s)

It would be great if someone could take a quick look and help since this problem is driving me crazy.  One thing I did find is an old thread (few years ago) that said something about setting image.noSmooth().  When I try to access this, it says that it doesnt exist or somethign like that.

Thanks for the help
Re: resize hard edges
Reply #5 - Jun 2nd, 2009, 11:06pm
 
Hard to run your code without your images...
Anyway, you can't do img.noSmooth() but you can do grph.noSmooth(): use a PGraphics instead of a PImage (a PGraphics is a PImage with added operations).
Re: resize hard edges
Reply #6 - Jun 3rd, 2009, 12:16am
 
Sorry but I have about 50k images so I couldnt include them all.

a workaround would be to comment out any line that loads an image (16 and 26)
and then replace line 28 with
temps = loadImage("test.png");
and save the png I linked above into your data folder as test.png (line 26 was a test line that cycled through 100 pictures in a gradient to see if it worked).
It wont really do anything but it should display the resized image.

I will give the PGraphics thing a try

EDIT: I looked at PGraphics, and my understanding is that it is basically an off screen buffer.  How do I load an image to it?  pgrh.image(xxx)?  Will this work any differently than just setting noSmooth in the frames I am rendering to?
Re: resize hard edges
Reply #7 - Jun 3rd, 2009, 2:13am
 
otc wrote on Jun 3rd, 2009, 12:16am:
Sorry but I have about 50k images so I couldnt include them all.
Of course! :-)
Workaround might not show the problem if the image isn't right.
Ah, I just found on my image folder something appropriate (a bunch of vertical black lines).

Let see...
If I do:
size(500, 500);
PImage img = loadImage("E:/Documents/Images/lines.gif");
img.resize(img.width * 2, img.height * 2);
image(img, 0, 0);

I get aliased lines, the issue you want to avoid.

If I do:
size(500, 500);
PImage img = loadImage("E:/Documents/Images/lines.gif");
image(img, 0, 0, img.width * 2, img.height * 2);

the problem disappear, since smooth is off by default on the main graphics.
But you might want to avoid resizing on each drawing, or have some other reason to do it once.

So you can do something like:
size(500, 500);
PImage img = loadImage("E:/Documents/Images/lines.gif");
PGraphics pg = createGraphics(img.width * 2, img.height * 2, JAVA2D);
pg.beginDraw();
pg.image(img, 0, 0, img.width * 2, img.height * 2);
pg.endDraw();

image(pg, 0, 0);

Again, smooth is off by default here.
Re: resize hard edges
Reply #8 - Jun 3rd, 2009, 7:37am
 
Thanks a bunch, setting the image size at display rather than with a resize seems to work fine.  It doesn't work in P2D but I dont think that actually makes a speed difference (I cant test on my production system until later)

I don't care about resizing on each drawing as I am already reloading, resizing, and redrawing the image on each loop.

Having hard edges definitely conveys my data in a much more readable way
Page Index Toggle Pages: 1