set unwanted color to transparent - colors

let say photoA got 100 color, i want to generate a transparent photoB with only 10 wanted colors. by using -transparent of 90 colors is too troublesome, any idea ?
thanks TobiasE, your answer is helpful.
i try the command below,
convert map.gif +transparent "#26fffe" newmap.gif
but it show error msg below:
convert: unable to open image `#26fffe': No such file or directory.
any idea ?

If the colors you want to make transparent is similar to each other you can use the -fuzz setting.
If the colors you want to keep visible is similar to each other you can use the -fuzz setting and use +transparent instead of -transparent to invert the matched pixels.

Straight from the documentation:
-transparent
...
Note that this does not define the color as being the 'transparency color' used for color-mapped image formats, such as GIF. For that use -transparent-color

Related

How do I tint an svg in processing and preserve brightness?

I've been trying to figure this out for 2 days now, so I hope somebody can help.
I need to load in svg files that have multiple values of gray within them and tint them with colors. So for example, say the svg file is an image of a rock and has 4 values of gray. I need to be able to display the rock as red and keep the differences between values in the different child shapes. In other words, I would like it to work just like PImage.tint().
I see there are tint() and setTint() methods to PShape but I can't seem to get them to work. I also though about recursing through the child shapes and reading each color individually and recoloring appropriately, but I couldn't even figure out how to read the color out in a way I understand.
Help, anyone?
If you have it as an <img> you can use the CSS filter property with hue-rotate https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/hue-rotate
Or you add the svg directly to the html and add classes to your elements. Then you could change the colors in your script.
If this is a flat colour then you could use the alpha value in RGB colour value. See 'color transparency' in the following link: https://processing.org/tutorials/color/
The fill value is fill(red, green, blue, transparency)
I hope this helps. If you want to share code and have a reason for using PImage I'd be happy to have a look.

Graphics program that will generate a common palette from multiple jpgs

gimp has the ability to generate a palette from a loaded image. I am looking to have all images (i am not necessarily the author of these pictures) share a common palette since this makes it easier displaying them on an LCD screen.
is there a program that does this? or some script in gimp or imagemagick?
There are few ways to do this:
use dithering
with palette designed for dithering like default VGA or WEB palette. I do it like this:
my simple C++ dithering
on how to do this. There are also more sophisticated approaches for this out there just google dithering...
merge all images to single mosaic
and compute the palette for this big image containing all the images you want with tool you use now. After that just use this palette for each of the original images (or on the mosaic and then de-mosaic).
compute the palette yourself
You need to compute histogram of all images and then use some kind of clustering to lower the number of colors. To include more images to this just compute histogram for all the images (do not reset it between images) and the rest is same as for single image. So if you got access to the color quantization code of yours then just change the histogram part ... by adding loop through all the images you want (and clearing histogram just for the first image).
Here example of how I do the color quantization:
Effective gif/image color quantization?
I do not use gimp nor imagemagick so I can not help you there but now you at least know what to look for in their docs ...
I'm not sure what you are trying to do is applicable to JPEG images as they do not have a colour palette. However, a possible technique with ImageMagick at the command line would be to put all the images together, reduce the number of colours to whatever you want and then save that (minimised/de-duplicated) as a "palette" which you can apply to other images.
So, the first step is to extract a common palette, of say 250 colours:
magick image1.jpg image2.jpg ... +append -colors 250 -unique-colors palette.png
Now, before you display any image, map it to that palette:
magick image.jpg -remap palette.png result.png
You can also disable dithering, with:
magick +dither image.jpg -remap palette.png result.png
I have used PNG rather than JPEG throughout because of my issue with JPEG palettes, but you can try with your JPEGs using just the same commands. I would definitely suggest you use GIF, PNG or NetPBM PPM format to store the palette information at least.
Just for fun, let's try that with a picture of the White House:
Let's make a really poor palette of three colours - red, yellow and cyan:
convert xc:red xc:yellow xc:cyan +append palette.png
and apply it with dither:
convert whitehouse.jpg -remap palette.png dither.png
and again without:
convert whitehouse.jpg +dither -remap palette.png undither.png
As #Spektre points out in the comments below, you may be passing that palette to the LCD in some BYTE array or something like a lookup table. If that is the case, you can see the palette in human/ASCII terms like this:
convert palette.png txt:
# ImageMagick pixel enumeration: 3,1,65535,srgb
0,0: (65535,0,0) #FF0000 red
1,0: (65535,65535,0) #FFFF00 yellow
2,0: (0,65535,65535) #00FFFF cyan
And you can get a 9-byte file of the R, G & B values in binary like this - I am choosing to dump it in hex afterwards so you can see it:
convert palette.png -depth 8 rgb:palette.bin
xd palette.bin
00000000: ff00 00ff ff00 00ff ff .........

ImageMagick processing of scan images

I am uploading a picture of a document taken with my smartphone to my Linux server. On my Linux server I am using ImageMagick to cut the edges and do some processing (like gray color coding) to make it look like a scanned document.
Below is one sample image.
I want to trim the image so that only the paper is selected, and do further processing to make it look like a scanned image, similar to what a cam scanner does.
Note: I want the parameters for ImageMagick tool to be generic so that I can use the same command line options to process images taken under different conditions of light.
I agree with #Mark. However, I can offer a starting point that may help you get going in the right direction:
Isolate the Paper:
Assuming the paper is sufficiently contrasted against the background you can use something like:
## make the background transparent
convert 'input_image' \( -clone 0 -fill black -fuzz 10% +opaque "rgb(1,1,1)" -transparent black \) -delete 0 'transp_image'
You will have to change the rgb color values to match the 'white' color of the paper. The display command in imagemagick has a nice utility for this. Also you can play with the -fuzz percentage to isolate the paper only.
Remove the Background: Hopefully the above code will make all areas outside the paper transparent in which case you can trim away the background:
## trim the transparent background away
convert 'transp_image' -trim 'isolat_image'
From there you can do fancier things like changing the perspective. Try looking into -distort in imagemagick (http://www.imagemagick.org/Usage/distorts/#perspective). Though I am not sure how you would apply a distortion in a loop to pictures taken by hand -- each picture would probably require specific input parameters.
Good luck!

Photoshop alter colors in blue white

I'm trying to make an header in Photoshop but I want the image I use to only have two base colors.
Just like:
How do I make this happen? And is it possible to just adjust one layer?
Basics is use hue/saturation in Image>Adjustment>hue/saturation tick the colorise in the bottom and enjoy colouring

Convert image to indexed color with custom palette through console

I have image.png in truecolor,
palette.png (N colors, where N>256) or text file, where list RGB color palette.
How to get a picture with this palette?
If I use imagemagick:
convert image.png -remap palette.png remap_image.png
It does not work.
convert image.png -map palette.png remap_image.png
Gives a very bad quality. The image is very noisy. File size is bigger than before.
GIMP gives best quality:
Сonvert image to indexed color > use custom palette
But GIMP is GUI. I need to convert a lot images in the console without running the gimp and X.org.
Using a shared palette across multiple images requires a carefully crafted palette. If you don't take great care when using the palette of a single image across many images, the result will be poor.
This needn't be complicated though. If you have accesss to the GIMP (or other tool) which supports truecolor graphics, you can create a large image and fit all of the smaller images into it, then quantize the image to N colors, then use that palette as the source.
you should be able to closely mimic GIMP's behavior in the console using ImageMagick
Once you've got a truecolor image with all the colors you want to quantize,
# Create an 8-bit png from our source, with a 235-color palette as an example.
convert truecolor_source.png -colors 235 palette.png
# Create an 8-bit png from an arbitrary image and use the palette in palette.png
convert sample.png -map palette.png output.png
There are a number of options for down-sampling colors, like dithering. See the ImageMagickv6 example page for an excellent overview with example pictures and code.
Although I still don't exactly understand what you want to do, your currently most recent comment ("Yes, from RGB to palette will set independently. Need set correct quantity of colors"), it sounds like all you want to do is set a strict limit on the amount of colors of a bunch of images, but they don't need to use the same palette.
In that case, the solution is very simple:
convert sample.png -colors 135 output.png
Try playing with the quantization options if the result isn't to your satisfaction.
If the output image is too large for your liking, you can experiment with the -quality option.
If this still isn't satisfactory, please try to explain your goal in a more detailed manner.
Good luck!
cat photo.png | pngnq -s 1 > photoindexed.png
I tend to get good results with the "-remap" (single imge) or "+remap" (multiple images) functions in combination with "-colors". Read up on those functions here. Note that "with "-remap" you provide IM with the final set of colors you want to use for the image, whether you plan to dither those colors, or just replace the ones with their nearest neighbours.", meaning just remapping/replacing might not look good enough, as colors from the input image are simply replaced by those from the palette image. Some form of dithering will be necessary to distribute pixel color conversion errors throughout the output image, because not all colors in the palette match those of the input image.
I'd suggest you use the "-colors N" option for that. This will reduce your output image color count to a maximum of N. By default ImageMagick uses "-dither Riemersma" for this implicitly when you specify "-colors N". The are also other dithering options available.

Resources