unsharp mask

Behind the Unsharp Mask: The Secret World of Sharpening

Proper sharpening is a bit like black magic. We can't really sharpen an image any more than it already is. If it wasn't sharp when captured, there's nowhere the information needed can come from later on. What we can do is create the illusion of sharpness by exaggerating contrast along edges in the image. This added contrast makes the edges stand out more, making them appear sharper.

But why is it called "unsharp" mask, and just how does one use the darned thing?

To understand what this is all about, we'll need to go back to the beginning. The name has its origins, as do many things photographic, in the conventional darkroom. Creating a print the old-fashioned way involves exposing photosensitive paper by projecting onto it a negative of the desired image. In order to accentuate edges in a print and thus make it look sharper, the darkroom operator made something called an unsharp mask.

The technique consists of creating a weak, slightly out of focus positive transparency of the original negative. Rather than exposing the negative on photographic paper, it is instead exposed on another sheet of film. Thus, this new version will be a positive image. Since we recorded it slightly out of focus, if we sandwich it with the original piece of film, all the edges in the composite image will have slight halos in the exact opposite color of whatever is on the other side of each edge.

For example, a black object against a light gray background (a tree against the sky in a black and white image perhaps) will produce an original negative of a white tree against a dark gray sky. The halos that result from excessive sharpeningIf we print this negative, we'll end up back to a normal tree again since the print will be a positive image. If that print is made as a weak image on another sheet of film, it will still be black on light gray. If it is also slightly out of focus, we'll have a weak, slightly out of focus black-on-light-gray tree on our new film. This is our mask. If it were in focus the same as the original image, sandwiching the two together wouldn't have much effect. The original image would so much overpower the weak mask image, printing the two together would give us basically the same image we would get without the mask. But since the mask image is slightly out of focus, its tones will bleed a bit and give us halos surrounding all the edges in the image. These halos will be in the opposite tone of whatever is on the other side of each edge. When printed, we'll get the black tree against the light gray sky as we expect, but those halos will serve to darken the sky right along the edges of the tree, thus making the edges appear slightly sharper due to the added contrasts.

The same thing works in color printing in the darkroom too. An object of a given color will contribute a slight halo having the inverse color along the outside edges of that object. If not done to excess, we won't really see the halos when printed, but we will see an apparent increase in contrast and thus sharpness, for that object.

Now let's step over to the digital darkroom. When unsharp mask is employed in Photoshop, we don't really see the inverted mask layer. All we see is the end result. Internally, Photoshop (or Photoshop Elements) is still doing the same thing as was done in the wet darkroom, but since all the work is done for us behind the scenes, there's no visible "mask" in unsharp mask. Indeed, there's no visible "unsharp" either since the final image looks sharper, as we wanted it to. All we are left with is sharpening tool with the rather strange name of "unsharp mask."

OK, so much for the history and word etymology lesson; how does one use unsharp mask?

Photoshop's Unsharp Mask dialogTaking a look at the Unsharp Mask dialog we find three sliders labeled Amount, Radius and Threshold. Moving them around with the Preview box checked does have an obvious change on the results we will get, but it isn't immediately apparent how to optimally set each. In order to understand how to set them, let's look at what each does.

Amount controls how weak or strong the mask image that is blended in will be. Thus, it controls how much edge contrast will be added and how much apparent sharpness we will get. If set too low, we won't see any change at all, but if set too high, the inverted halos from the mask will be visible in the final image and it will look artificial. Most Photoshop users are familiar with the appearance of an over-sharpened image, having probably produced a few themselves while trying to figure out what to do with Unsharp Mask. You can't make an omelet without breaking a few eggs though.

Radius controls the degree of unsharpness the mask image will have. Thus, it determines the width of the halos the mask will produce. The higher the radius the more evident the sharpening effect will be. Set too low, the effect will be invisible or too subtle to be effective. The appearance of the halo will also vary with the content of the image since the amount of contrast already present will play a role.

Threshold selects how much adjacent pixels need to be to be considered an edge. Thus, it prevents sharpening of unimportant or incidental detail while reserving the effect for detail that should stand out. It separates signal from noise, if you will. Set too low, sharpening will be applied to every edge or change of tone throughout the image including such things as film grain. If set too high, no transitions will be viewed as being edges and no sharpening will result.

There are many schools of thought as to how to optimally set these sliders. Key to all of them though is to view the image at actual 100% size. At lower resolutions you will only see a portion of the result, not the effect itself. Also, while there are other times to sharpen, the bulk of sharpening is best done at final output resolution so do all your editing including resizing for print or web before sharpening. If you are creating a web graphic or other image destined for screen viewing, sharpen until the image looks right at full size. If you are sharpening in preparation for printing an image, you may find that slightly over sharpening will work well to compensate for any loss of sharpness printing itself may introduce. The need to do this will depend just how you print, so you will have to do a bit of experimenting to learn what works best for your printer. I find that current Epson drivers do a great job of retaining sharpness so little if any excess sharpening is required before printing. Sharpening is also dependent on image content. An image less inherent detail will generally tolerate more severe sharpening, while many with a great deal of detail will only require minimal sharpening since they will naturally look sharper to begin with.

Even though Amount is at the top of the set of controls in the Unsharp Mask dialog, you should generally start with the Radius control. An image with fine detail will need a lower Radius setting while one with less inherent detail can utilize a larger Radius. Start with a Radius between about 1.0 and 1.5 and go from there, lowering the setting perhaps to 0.5 or even lower for images that start with fine details, or raising it to perhaps 2.0 to 4.0 for images with lower levels of inherent detail.

If you have selected a small Radius setting, the halos will be narrow, so you will need a high Amount setting for them to have much effect. Conversely, if you are using a high Radius value, the halos will be wide and you will need a low Amount setting to avoid them being obvious. Once you understand what the controls actually do, you should be able to tweak things visually using the 100% view. Play with a few of your own images until you get the hang of things.

After settling on ranges for Radius and Amount, decrease the Threshold value until unwanted noise or other artifacts start appearing where you don't think edges should be, then raise it slightly. The exact setting you end up with will be highly dependent on the content and source of the image you are sharpening. In general, scans from slides will require a higher Threshold value than will digital captures to prevent problems from film grain from showing.

Some softness is inherent in digital capture or scanning. Printing, whether in the wet darkroom or digital darkroom can also introduce a slight softness if not compensated for. While unsharp mask can work wonders for restoring the crispness we expect, it does have its limits. Don't try to use Unsharp Mask as a substitute for proper field technique. Photoshop can make a good image better, but trying to make an out-of-focus image sharp is beyond what it is intended for. Hopefully though, what I've gone over here will help you when trying to optimize those images you want to truly make their best.


转载于:https://www.cnblogs.com/cloudseawang/archive/2007/06/05/771606.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 OpenCV 对图片进行处理,需要先在项目中导入 OpenCV 库。可以在项目的 build.gradle 文件中添加以下代码: ``` dependencies { implementation 'org.opencv:opencv-android:3.4.1' } ``` 接着,在 Java 代码中加载 OpenCV 库: ``` if (!OpenCVLoader.initDebug()) { // Handle initialization error } ``` 假设要实现一个名为 `enhanceImage` 的成员方法,接收一个 Bitmap 对象作为参数,返回处理后的 Bitmap 对象。该方法可以按如下方式实现: ``` public Bitmap enhanceImage(Bitmap input) { // Convert bitmap to Mat object Mat inputMat = new Mat(); Utils.bitmapToMat(input, inputMat); // Convert image to grayscale Mat grayMat = new Mat(); Imgproc.cvtColor(inputMat, grayMat, Imgproc.COLOR_BGR2GRAY); // Apply histogram equalization to increase brightness and contrast Mat equalizedMat = new Mat(); Imgproc.equalizeHist(grayMat, equalizedMat); // Apply unsharp mask to increase sharpness Mat blurredMat = new Mat(); Imgproc.GaussianBlur(equalizedMat, blurredMat, new Size(0, 0), 10); Mat unsharpMask = new Mat(); Core.addWeighted(equalizedMat, 1.5, blurredMat, -0.5, 0, unsharpMask); Mat sharpenedMat = new Mat(); Core.add(equalizedMat, unsharpMask, sharpenedMat); // Convert Mat object back to bitmap Bitmap output = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(sharpenedMat, output); return output; } ``` 该方法的具体实现步骤如下: 1. 将输入的 Bitmap 对象转换为 Mat 对象。 2. 将彩色图像转换为灰度图像。 3. 对灰度图像应用直方图均衡化,增加图像的亮度和对比度。 4. 对均衡化后的图像应用 unsharp mask 滤波,增加图像的清晰度。 5. 将处理后的 Mat 对象转换为 Bitmap 对象,并返回。 请注意,在实际使用中,可能需要根据具体情况对方法进行调整,以达到最佳效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值