Which function should i use to convert an image to grayscale using GOIMAGICK in GO - go-imagick

I want to convert an image to grayscale using magickwand in GOIMAGICK, but which one should I use: BlurImage(radius, sigma float64) error or BrightnessContrastImage(brightness, contrast float64) error?

With ImageMagick MagickWand it goes like this:
MagickQuantizeImage(image_wand,256,GRAYColorspace,0,MagickFalse,MagickFalse);
So, why not go for QuantizeImage?

Related

how to use golang compress and resize a gif

Is there has method or lib to compress and resize a gif use golang?
ps: I was tried bimg, but it not support gif.
see doc https://golang.org/pkg/image/gif/#GIF
func DecodeAll(r io.Reader) (*GIF, error)
now you can get a GIF struct
type GIF struct {
Image []*image.Paletted // The successive images.
then you can resize each of Image in GIF.
for _,img:=range gif.Image{
resize(img)
}
PS: image.Paletted implemented image.Image, so you can use https://github.com/nfnt/resize to resize the Image.
I've never used but I think you can read/write GIFs using the std library (import "image/gif"). Then resize using something like "resize" (see Go Resizing Images)

Which function should i use to remove(strip) colorspace of a image using Imagemagick magickwand

I actually wanted to remove the colorspace of the image. However, which colorspace type should I use in the transformimagecolorspace method COLORSPACE_UNDEFINED or any thing else?

How to create optimised and progressive Images (JPG, PNG) in Go lang

I am using the following code in Go to resize my images in JPEG and PNG format. So, how do I convert them to progressive and optimized using Imagick. I'm using ImageMagick 6.9.3-8 Q16 x86_64 on ubuntu 14.04
I am saying optimized reason being I used the following command to test whether image size gets reduced or not. But, it increases the output file size.
Command :
convert -strip -interlace Plane input-file.jpg output-file.jpg
Go code :
size = fmt.Sprintf("%dx%d^+0+0", w, h)
tx := mw.TransformImage("", size)
tx.SetImageGravity(imagick.GRAVITY_CENTER)
offsetX := -(int(w) - int(tx.GetImageWidth())) / 2
offsetY := -(int(h) - int(tx.GetImageHeight())) / 2
err := tx.ExtentImage(w, h, offsetX, offsetY)
Your convert command line strips the image and gives it a planar interlace scheme. An equivalent Go code should call mw.StripImage() and mw.SetImageInterlaceScheme(INTERLACE_PLANE).
[edit] Are you trying to follow this example ? If so, -interlace Plane is responsible for making the image progressive, but this doesn’t make it any smaller. The part that does that is -quality 80, which you can implement in Go by calling mw.SetImageCompressionQuality(80).
Use ResizeImage instead
tx.ResizeImage(w, h, imagick.FILTER_LANCZOS, 1)
See the resizing example

ImageMagick, Convert command degrades image actual Quality

I have been trying to convert JPG image which is in CMYK format to sRGBformat with imagemagick library in Ruby on Rails.
But unfortunately, observed that quality of the image degraded after convertion of image by following command:
MiniMagick::Tool::Convert.new do |convert|
convert << attachment.tempfile.path
convert.merge! ["-colorspace", "srgb"]
convert << attachment.tempfile.path
end
Is there anything missing here? and looking forward to avoid the deviation.
Please let me know your ideas.
You can try to use the ImageMagick -profile option for better conversion:
convert image.jpg -profile sRGB.icc rgb_image.jpg
You can look here for more details on ImageMagick.

How to Save an image in matlab

I use the below command to display the image
imshow(img,[]);
when i use the following command to save the image it is saved as an empty white page
imsave;
how to save the image in this case any command would do
You are probably running into an issue with matrix type and range. If img is type double it needs to be scaled between 0 and 1.
A common issue is to load an image in uint8 (scaled between 0 and 255), convert to double in order to do some processing on it, without scaling, and then try and save it out. When you do that, MATLAB tries to convert back to uint8, and any values in the image outside the [0 1] range are clipped. On many images this means that the file comes out all white.
To get around this, use functions like im2double and im2uint8 rather than just double or uint8 when converting images.
Try at the command line the difference between:
img = imread('pout.tif');
img = double(img);
imshow(img,[]);
imsave;
and
img = imread('pout.tif');
img = im2double(img);
imshow(img,[]);
imsave;
Convert image data into an actual image and try again:
h = image(img); %Convert to object
imsave(h); %Save image object
Notice that if you close the figure window generated by image(), the object is deleted and the handle has will point to nothing. Though this may be beyond of what you are asking for.
Hope this adjustment solved your problem
First convert the image to rgb using
img1=label2rgb(img);
then again convert the image into an gray image using
img2=rgb2gray(img1);
then u can use imshow to show the image and save it using imsave
imshow(img2);
imsave();

Resources