losing quality when resizing with ImageResizer - c#

I'm using the ImageResizer .net library. It works as expected, but one image messes around.
I've uploaded the image below. I've already tried some things like format=jpg&quality=100, only width=220, also different sizes, but it always adds this blurry border around the image.
The original image is a png.
This one is the original image:
This one is resized by the ImageResizer:
And this one is resized with photoshop:
EDIT:
If you're running into the same issue. Try to set up the SpeedOrQuality Plugin. I've set it to speed=3 and the image is sharp again.

Vector graphics require different resampling algorithms than photographs.
ImageResizer V4 includes higher quality image resampling options under the FastScaling plugin.
For graphics (non-photographic images), I suggest playing with &f.sharpen=0..100, &down.preserve=-5..5, and &down.filter=Robidoux. Make sure &fastscale=true and FastScaling is installed.
You can certainly find a good configuration for your rasterized vector art and set up a preset for it. FastScaling is capable of much better resampling than Photoshop - on par with Lightroom, in fact.
Enabling fastscaling alone helps substantially (?width=200&fastscale=true):
Adding sharpening gives a very clear result: (?width=220&fastscale=true&f.sharpen=100):
Visibly crisper than Photoshop:

Each time you save a jpeg, you loose quality (the image is reencoded).
I would recommend using the same quality as the original image was save against, it should give the best results.
Using a higher quality is not recommended as it will artificially try to improve quality, mistaking approximations done by previous encoding for details, resulting in things like the blurry border.
Aside that, usually, one should not use a quality over 95 for jpeg encoding.

Related

Resize image with scale and crop in C#

When I upload an image, it is quite big some times, I have to create its thumbnail in a specific way.
What I want is if I declare the size of 96x69 for the thumbnail, those uploaded images which are scalable to this resolution should be scaled, and those uploaded images which are quite different in wxh, example 1000x1000, they should be cropped to maximum better scalability.
Is there any fast library or built in code as I have tried to do in my own way but it is not that perfect?
I strongly recommend ImageResizer which can be found freely on the Nuget. Basically, resizing images is a sophisticated procedure that may be included variety techniques such as cropping, scaling, resizing, moving, trimming, etc. that implementing each of these methods is not an easy job. Hence, it's better to use image-resizer.
you can use jquery for solving this problem. If its feasible in your project to do it client side.
Check these link here..
http://www.jqueryrain.com/demo/jquery-crop-image-plugin/
and
https://code.google.com/p/resize-crop/ this one is best and easiest i guess.
If you want to do it server side for some reason, then have a look on solution mentioned in this question.
Which free image resizing library can I use for resizing and probably serving images?
Hope this will solve your problem.

Content-Aware Image Cropping with C#

I am working on a CMS like project which users can upload images with contents. I have to create thumbnails for the uploaded images on the fly. Lets say the thumbnail size as 125x75
I can resize images without problem but when it comes to crop operation several problems occur. My resize and crop procedure works like this:
Load the original image.
Resize the image to desired size preventing the original aspect ratio depending on the given maximum width or height
If the result image has a different aspect ration than the output aspect ratio than a centered crop operation is applied.
But what I want to achive is a content-aware cropping as described in Jue Wang's article Opticrop: Content-aware Cropping with PHP and ImageMagick
Is there any way to do it with C# or is there a library that can do this operation.
Note: I do not want content-aware resizing. Content-aware resizing (seam craving) can be done with ImageResizing.net SeamCarving plugin
If you are using the ImageResizing.net framework, the WhitespaceTrimmer plugin may be a good starting point I think.
If you want to write the code yourself, this Gist shows a good solution using entropy but is written in Ruby.

Native WPF vs. Custom DirectX for displaying large images

I need to speed up my image viewer, and wondering if I should be looking into creating my own DirectX control to do so.
My image viewer displays medical images. They can be pretty large. We're talking 55mb when it comes to mammography. The pixel data is 16bit greyscale stored in a ushort array. Without getting into the gory details, my current approach is loading the pixel data into an ImageSource, and using the WPF Image control.
I've never done anything with DirectX. Is it worth diving into it? Would it be any faster than the native WPF stuff? If so how significantly? Or, should I just forget about DirectX and look into areas where I can improve my current approach?
Before somebody says so, I know WPF utilize DirectX. I'm wondering If removing the WPF layer and writing the DirectX myself will improve performance.
I have some experience drawing multi-gigabyte satellite and chart imagery. Working with imagery around 55MB should probably work okay even without trying to optimize it too much. You haven't really given enough detail to recommend one alternative over the other, so I will give my opinion on the pros and cons.
Using 2D windows APIs will be the simplest to implement and should always be fast enough if you don't need to rotate and simply want to display an image and zoom and pan around. If you treat it as one large image the performance will not be as good when you zoom out if you are drawing with halftoning to give a nice smooth image. This is because it will effectively have to read all 55mb of image every time it draws.
To get around this performance issue you can make multiple bitmaps, effectively mip-mapping your image. As you zoom out you can pick the reduced resolution image closest to the resolution you are trying to draw . If you are not familiar with mip-mapping here is a Wikipedia link:
http://en.wikipedia.org/wiki/Mipmap
Implementing it with DirectX will be 10x as difficult. Different graphics hardware has different maximum texture sizes. Most likely you will need to break your image up in to multiple textures to draw and you will also have to keep track of render states, viewing matrices, etc.
However, if you do use DirectX, you can implement lots of real-time photo adjustments You can do real-time rotation by simply adjusting view matrices. You can do real-time contrast, brightness, gamma, and sharpness easily in a pixel shader.
There are two other API's I might suggest. If you are willing to limit yourself to Vista or later then Direct2D would be a little simpler than Direct3D. Also if you ever will need to implement it on a non-windows platform I would suggest using OpenGL instead. My current project is in Direct3D because a few years ago when we started it OpenGL was falling behind and I didn't forsee the popularity of Android devices. I now wish we had used OpenGL instead.
Try profiling to see where WPF is spending its time. Are you displaying the images at their native resolution? If not it might be worthwhile to do some preprocessing and create 1/2 resolution versions.

Zooming an extremely large image

Is there any predefined control in WPF or VS2010 to implement the Image Zooming functionality (like Googlemaps) for a bitmap displayed over a panel using C#? My bitmap will be minimum 8GB in Size.
Thanks in advance
Murali
There is DeepZoom for Silvelight. There is no such thing in WPF. It was planned for WPF4, but removed before RTM.
Update:
Loading images of this size is pretty uncommon. You should consider tiling as others suggested. Also consider if you really need load all data at once. If the image has size of for example 30000x30000 then the user do not really need/can't to see all this data. Use tiling and appropriate image format (jpg etc) for each zoom level.
Relevant links:
Single objects still limited to 2 GB in size in CLR 4.0?
Pushing the Limits of Windows: Physical Memory

Slice up an image into tiles

Given a loaded Bitmap object. I want to slice up this image into 256x256 tiles and save out each tile as a jpg file.
You may think this as a Silverlight Deep Zoom sort task and you'd be right.
I've got a solution using WPF but I would prefer a solution that would work in the .NET 2.0 framework. GDI+ is not somewhere I've spent any amount of time.
Anyone know how I could go about this? I can't seem to find a "Create Bitmap from a specified rectangle sort of method". I'd be surprised if one doesn't exist but perhaps I can't see the wood for the trees.
You can use Bitmap.Clone(Rectangle, PixelFormat) to crop out a 256x256 region of a source image. This works in .NET 2.0.

Categories

Resources