Page 1 of 1

Smoothing an image but keeping it's sharp edges intact

Posted: 2013-01-28T13:29:40-07:00
by gabew
I need to make several images 4 times bigger, and I need them to fit normally in a background, without anti-aliasing or anything similar - I need it's outside to be sharp. Now, I know -scale does exactly that, but -resize makes it look infinitely better. I can't however use -resize because it blurs the outside shape of the image too, making it not work the way I want with the background. My question is the following:
Is there a way to make an image be blurred on the inside, the same way it is when you -resize it, but still have perfectly sharp edges, the same way it is when you -scale it?

I'm quite sure I should be using masks to do this, but I really don't have any idea how to, so I'm asking you guys.

Examples:
Resized:
Image
Scaled:
Image
(I used -median 10 too on both so they look better)

The image should look smooth as the first one, but have sharp edges and fit on a background that doesn't support transparency just like the second.

Thanks in advance!

Re: Smoothing an image but keeping it's sharp edges intact

Posted: 2013-01-28T14:05:11-07:00
by snibgo
I'm not entirely clear what you are asking. Can you provide the image you want enlarged?

Maybe you want to:

1. Create an image of the red background, transparent where the hand and gun were. Scale this 400%.

2. Resize the original 400%.

3. Place image (1) over image (2).

Re: Smoothing an image but keeping it's sharp edges intact

Posted: 2013-01-28T14:52:50-07:00
by gabew
The red background is just an example, I actually want to use it in a game that doesn't work with partial transparency, only boolean, so I need it to have indeed a transparent bg, but one that would look normal if I were to fill it with a random color or paste it over a background image. Yes, I assume what you said would work perfectly for what I want. The thing is - I need to do that in batch. Is there any scripted way to make something similar to that easily?

This is the picture I'm using as an example:
Image

Re: Smoothing an image but keeping it's sharp edges intact

Posted: 2013-01-28T15:26:22-07:00
by snibgo
Ah, you want to enlarge the image, but ensure the transparency is binary rather than a transition?

Code: Select all

convert gunHand.png -resize 400% -channel A -threshold 50% gh400.png
You could use mogrify to do many images in one command.

Re: Smoothing an image but keeping it's sharp edges intact

Posted: 2013-01-29T20:37:49-07:00
by gabew
Alright, look:
Image
I need to find a way to make the initial small image into something like the one above I made manually. That one looks EXACTLY the way I need it to - somewhat blurred just like when -resized, but with sharp pixelated edges just like when -scaled.

Is there any kind of simple way to make something like that?


(Thanks for your help, snibgo, but using the exact threshold example you posted me gave this output)

Re: Smoothing an image but keeping it's sharp edges intact

Posted: 2013-01-29T21:20:51-07:00
by snibgo
On IM v6.7.9 and 6.8.1, on Windows 7, I get a different output to you. What version are you on?

I am still unclear what edge result you want. The edges in your "manual" version (which I can get close to with "-morphology dilate disk:8") don't look like what I get with "-scale".