Smoothing an image but keeping it's sharp edges intact

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
gabew
Posts: 3
Joined: 2013-01-28T12:54:21-07:00
Authentication code: 6789

Smoothing an image but keeping it's sharp edges intact

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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).
snibgo's IM pages: im.snibgo.com
gabew
Posts: 3
Joined: 2013-01-28T12:54:21-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
gabew
Posts: 3
Joined: 2013-01-28T12:54:21-07:00
Authentication code: 6789

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

Post 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)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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".
snibgo's IM pages: im.snibgo.com
Post Reply