How to make Duotone Effect by GraghicsMagick? - effect

In ImageMagick, I can do "Duotone" effect by following command,
convert rose_grey.jpg -fill blue -tint 100 rose_blue.jpg
But in GraphicsMagick, it doesn't work.
I am stuck: How to do it? Thanks.

Related

R Magick Package Image_Write Saves Tiff Images in Gray Instead of RGB

I have a very large number of images that need to be cropped slightly (by 1 pixel either height-wise or width-wise) in order to do further image-processing on them.
I'm trying to use the Magick package in R to do so, but running into an issue where any images that are gray are saved by Magick in grayscale instead of RGB. I see that people have asked similar questions here and here, and I have tried the solutions offered to no avail. For some reason, when doing Image_Write, setting the defines colorspace to auto-grayscale off and type to truecolor does not work and the images are still saved as grayscale instead of RGB format.
Here is the code I'm trying to use:
crop <- function(a,b) {
image <- image_read(a)
cut <- image_crop(image, b)
image_write(cut, path = a, format = "tiff", defines = c('colorspace:auto-grayscale' = 'false', 'type:truecolor' = 'on'))
}
runcrop <- mapply(crop, mydat[,1], mydat[,2])
Where the input (mydat) is a table with two columns: the path to the image and the pixel size I need the image cropped to. Any image taken in black and white (CH4) is saved as a grayscale output, while all the other channels are correctly saved as RGB images after cropping.
Here is a small excerpt from the table:
> mydat
imtocrop WxH
[1,] "./01 10245 XY01_Fused_CH1.tif" "2288x1218+0+0"
[2,] "./01 10245 XY01_Fused_CH2.tif" "2288x1218+0+0"
[3,] "./01 10245 XY01_Fused_CH3.tif" "2288x1218+0+0"
[4,] "./01 10245 XY01_Fused_CH4.tif" "2288x1218+0+0"
[5,] "./01 10245 XY01_Fused_Overlay.tif" "2288x1218+0+0"
And here is an example image to recapitulate the error: https://www.dropbox.com/s/8m93vflnf6rd6ao/01%2010245%20XY01_Fused_CH4.tif?dl=0
The cropping formula I've written works perfectly, but I can't seem to get Image Magick to save these tiffs as RGB instead of grayscale. I've tried both 'false' and 'off' for auto-grayscale, I've tried 'true' and 'on' for truecolor. I've also tried using only the truecolor option, without the colorspace option (as suggested on ImageMagick's documentation site here). Nothing I do seems to convince Image_Write to output as RBG instead of grayscale. Please let me know if you have any ideas that might fix this error, thanks!
I have no knowledge of R, but am trying to move my knowledge of ImageMagick towards your knowledge of R and maybe we an reach the target of sorting out your problem somewhere in the middle...
Let's make a simple 640x480 solid black image with ImageMagick in the Terminal, and pipe it into exiftool in TIFF format to check its depth and whether it is greyscale or colour:
magick -size 640x480 xc:black tif:- | exiftool - | grep -E '^Bits|^Photometric'
Bits Per Sample : 16
Photometric Interpretation : BlackIsZero <- means GREYSCALE
Ok, not surprisingly, our black 640x480 rectangle came out in greyscale with 16-bits per sample because my ImageMagick was compiled with Q16. Let's rectify the 16-bit-edness:
magick -size 640x480 xc:black -depth 8 tif:- | exiftool - | grep -E '^Bits|^Photometric'
Bits Per Sample : 8 <--- that's better, 8-bit
Photometric Interpretation : BlackIsZero <--- still greyscale
Ok, now let's force the black image to become RGB:
magick -size 640x480 xc:black -type truecolor -depth 8 tif:- | exiftool - | grep -E '^Bits|^Photometric'
Bits Per Sample : 8 8 8
Photometric Interpretation : RGB
My hope is that you can find the corresponding settings/switches/options in R Studio now that you know what they look like.
Another option might be to "shell out" with system() and just use the command-line interface:
magick INPUT.TIF -crop WIDTHxHEIGHT+xoffset+yoffset -type truecolor RESULT.TIF
Note that I am forcing TIFF format and piping to exiftool for simplicity of demonstration. If you are testing in your Terminal, you can write straight to a TIFF file with:
magick -size 640x480 xc:black image.tif
You can also set lossless compression with:
magick -size 640x480 xc:black -compress LZW image.tif

add background to a gif containing images of different sizes (R magick)

I would like to add an image background to a gif which contains images of different sizes like this beautiful christmas ball.
Here is the code i tried :
#install.packages("magick")
library(magick)
setwd("C:/Users/...")
christmas <- image_read('christmas.gif')
background <- image_blank(250, 250, color = "red")
frames <- image_composite(background, christmas, offset = "+0+0")
animation <- image_animate(frames, fps = 5)
image_write(animation, "output.gif", format="gif")
And here is the horrible result !!
The problem is that the 3 images of the ball gif are not of the same size so the images are moving when adding a background image.
> christmas
format width height colorspace matte filesize
1 GIF 216 249 sRGB TRUE 47656
2 GIF 202 233 sRGB TRUE 47656
3 GIF 200 214 sRGB TRUE 47656
I didn't find how to fix this problem... : If you could help me before christmas it would be great !!!
Thanks !
Your problem is likely that you need to coalesce the frames to fill them out to the same size. Then later optimize them again. In ImageMagick, I would do:
convert ornament.gif -coalesce -background red -alpha background -alpha off -layers optimize ornament2.gif
See
http://www.imagemagick.org/script/command-line-options.php#coalesce
http://www.imagemagick.org/Usage/masking/#alpha
http://www.imagemagick.org/Usage/anim_opt/#optimize
Sorry I do not know the equivalent commands in RMagick. But they likely have similar names. Hopefully, this will get you pointed in the right direction.

Image to pencilsketch using graphicsmagick

I am new to imageprocessing. I want to convert an image to pencilsketch. I want to know how can i achieve the same with Graphicsmagick. Thanks in Advance.
It would be somewhat easier with ImageMagick than GraphicsMagick, as Anthony Thyssen has put together some excellent examples - but they rely on ImageMagick capabilities such as "aside-processing" in parentheses which GraphicsMagick lacks. They are here.
However, you can do fairly simplistic stuff with GraphicsMagick. Let's start with this picture of the White House:
gm convert whitehouse.jpg -edge 1 -negate -normalize -colorspace Gray -blur 0x0.5 sketch.png

graphicsmagic compare the opacity of the diff image

If I do the following on the command line:
compare out1.png out2.png diff\out1.png
The diff image is very light and it's easy to spot the differences (even if they are only a couple of pixels).
I can't seem to get the same result using gm:
gm compare -colorspace GRAY -highlight-color red -verbose -file
diff\out1.png out1.png out2.png
This will have the red difference stick out a little but the resulting image is not transparent (alpha opacity?) like with the compare command. I think compare came from installing graphicsmagick so it uses gm but with what parameters?
[UPDATE]
I just found that compare.exe is from Imagemagic
The reason I needed this is because I was using gm with webdriverjs (selenium-webdriver for node) to compare my dev environment with the production/staging site.
Because gm.compare did not work with imagemagick I used graphicsmagick but solving the bug with gm was easier than trying to figure out how to use graphicsmagick.
So even though the actual question is not answered I solved the problem.
Maybe I'll turn this question into a wiki for webdriverjs.

How to convert png8 in GraphicsMagick

I want to convert an input 8-bit PNG image to 8 bit.
I have tried using GraphicsMagick. But I don't know how to convert png8 in GraphicsMagick.
When I use the command as such:
gm convert source.png png8:output.png
it return the message
gm convert: Invalid background palette index (output.png).
My version is GraphicsMagick 1.3.20 2014-08-16 Q8 .
Try using the "-colors 254" option, e.g.,
gm convert source.png -colors 254 png8:output.png
The "png8:" color reduction is somewhat quick-and-dirty and doesn't do nearly as good a job as the slower -colors option, with either GraphicsMagick or ImageMagick.

Resources