Tag Info

Hot answers tagged

15

image = Import["http://i.stack.imgur.com/UNXEV.jpg"]; n = TotalVariationFilter[image, 0.05] b = LocalAdaptiveBinarize[n, 50] s = DeleteSmallComponents[ColorNegate[DeleteSmallComponents[b, 20^2]], 20^2] (d = DistanceTransform[s]) // ImageAdjust m = MaxDetect[d, 10] (w = WatershedComponents[ColorNegate[d], m]) // Colorize c = ComponentMeasurements[w, ...


15

A somewhat revised approach. First define the colours and create column images from them. There are four block colours and one striped. blue = {0.15, 0.23, 0.33}; red = {0.77, 0.16, 0.17}; paleblue = {0.50, 0.60, 0.63}; beige = {0.96, 0.90, 0.69}; cols = Image[Table[Transpose[{##}], {60}] ~Flatten~ 1] & /@ {{blue}, {red}, {paleblue}, {paleblue, ...


13

Here's my attempt, using @RahulNarain ColorFunction with different colors: obamaize[image_, text_] := Module[{colored = Colorize[image, ColorFunction -> (Piecewise[{{RGBColor[{30, 60, 88}/255], # < 0.5}, {RGBColor[{202,36, 40}/255], # < 0.67}, {RGBColor[{124, 151, 168}/255], # < 0.75}, {RGBColor[{240, 232, 173}/255], True}}] ...


11

This appears to work nicely: DeleteSmallComponents @ LocalAdaptiveBinarize[ColorNegate[img], 10, {1, 1, 0.02}]


10

Sorry for bumping a two-year-old question, but I asked about it and people said it was okay! Since, as the question states, "true" vectorization of the whole image is a tough problem, how about we break up the image into little blocks and vectorize those? I'll take one of the Kodak test images: img = ...


5

First off, here's @kale's excellent answer modified with a bilateral filter to smooth it a little: kalesObamaize[image_, text_] := Module[{colored = Colorize[BilateralFilter[image, 2, 0.5], ColorFunction -> (Piecewise[{{RGBColor[{30, 60, 88}/255], # < 0.5}, {RGBColor[{202, 36, 40}/255], # < 0.67}, ...


5

In version 10 there is now a RemoveBackground function, with more options and parameters than you could dream of. Without any help, it will do this: i1 = Import@"http://i.stack.imgur.com/LKZfw.png"; RemoveBackground[i1] but with some encouragement, in the form of a hint about the background's colour, or some marker positions to indicate the background, ...


4

shape1 := Graphics[{#, Circle[{0, 0}, 1.5], Disk[]}, ImageSize -> 10] &; shape2 := Graphics[{Lighter@#, Disk[]}, ImageSize -> 10] &; ClearAll[lOF]; lOF[nOfOverlays_, colors_List, opts : OptionsPattern[]] := DynamicModule[{layer = 1, pts = ConstantArray[{{100, 100}, {700, 700}}, nOfOverlays], col = ...


4

RemoveBackground works well only when the foreground does not have the same (or very similar) color as the background. Here is an alternative approach using GrowCutComponents. Markers were generated using Mask Tool from Image Toolbar. g = ImagePad[ExampleData[{"TestImage", "Girl2"}], -10];


4

The other two excellent answers to this question were created before the arrival of version 10.0 and the RemoveBackground function. Out of curiosity I tried this new function on the test image, to see if it delivered on its promise. g = ImagePad[ExampleData[{"TestImage", "Girl2"}], -10] The function is set up to work without settings, presumably for use ...


4

As requested: i = Import["http://i.imgur.com/Y87duSz.jpg"] n = TotalVariationFilter[i, 0.02] e = EdgeDetect[n, 1, 0.02] (d = DistanceTransform[ColorNegate[e], Padding -> 0]) // ImageAdjust m = MaxDetect[d, 2] (w = WatershedComponents[ColorNegate[d], m]) // Colorize Kind of ugly with the rough edges, but there you go.


4

You can get a reasonable result by converting to HSB space and removing the hue channel (ColorSeparate then use ImageAdd to recombine the saturation and brightness), followed by an adjustment to the contrast and gamma (play around with the values to get something you like): image = Import["http://imgur.com/mRRhOgo.jpg"]; pencil = ImageAdd @@ Rest @ ...


4

This is too long for a comment. The difficulty with the example image is that it is not "clean" in the sense that it contains pixel gradients. There are 256 colors present despite the fact that there are only 50 triangles. This is why you get the imperfect output from EdgeDetect, and it is going to make any image processing more difficult. We can see this ...


3

Update: Here's what I came up with trying to color every triangle independently regardless of its brightness. Create a marker for ImageForestingComponents: dim = 5;(* number of rectangles *) marker = Rasterize[ Graphics[{White, Point /@ Table[Sequence @@ {{x, y + .05}, {x, y - .05}}, {x, .5/dim, 1 - .5/(dim), 1/dim}, {y, .5/dim, 1 - ...


3

I enjoy representing colour images with tilings, preferably non-periodic ones. Alternatively, one can use overlapping tiles to give a slight 3D effect. Here is some example code. TranslateObject[p_, {x_, y_}] := Map[{x, y} + # &, p, {2}] HouseHexPolygon[s_, 0] := Polygon[s*{{1/2,-1}, {3/2,0}, {3/2,1}, {-1/2,1}, {-3/2,0}, {-3/2,-1}}] ...


3

In order to apply a function to every element we can use Map with the level specification: Map[If[MemberQ[keep, #], #, 100] &, matrix, {2}] Another option using the Listable attribute: Function[{x}, If[MemberQ[keep, x], x, 100], Listable]@matrix; This turned out to be a lot slower though. I ran these on Michael E2's test case and the Listable ...


3

This is a followup to @Simon Woods' answer and @rm -rf's comment Now if only there was a way to fix that hatch from bleeding into the bg... There is! Let's create a face mask: i = Import["wolfram.jpg"]; face = FindFaces[i][[1]]; facemask = Graphics[{White, Circle[Mean[face], (Mean[face] - face[[1]])*{.8, 1.2}]}, Background -> Black, ...


2

Here a different approach, that mainly uses the build in ImageEffect "Posterization" and ColorReplace: First the image is imported, the background removed and blured a bit: img1=Blur@*RemoveBackground@Import["http://hplussummit.com/images/wolfram.jpg"]; Than the ImageEffect is applied: img2=ImageEffect[img1,{"Posterization",2}]; The dominant colors are ...


2

Using Rahul's idea and a bit of blurring: img = Import["http://hplussummit.com/images/wolfram.jpg"]; bimg = Blur[img]; Colorize[ bimg, ColorFunction -> (Piecewise[{{Darker@Blue, # < 0.5}, {Red, # < 0.67}, {Darker@LightBlue, # < 0.75}, {LightYellow, True}}] &)]


2

Here one approach: im=Import["http://hplussummit.com/images/wolfram.jpg"]; mb=MorphologicalBinarize[im]; cb=ChanVeseBinarize[im]; ia1=ImageAdd[ColorReplace[im,ColorNegate[mb]->Darker@Blue],mb]; ia2=ImageAdd[ColorReplace[RemoveBackground[im],ColorNegate[cb]->Darker@Red],cb]; ...


2

I shall not attempt to replicate the exact function of your code but rather to address the problem posed in text of your Question. As a starting point I suggest you build a Dispatch table of the replacements you wish to make and then apply it with Replace. First some sample data: SeedRandom[0] m = RandomInteger[66, {1024, 1024}]; keep = Array[Prime, 18]; ...


2

SelectComponents is pretty fast but it labels the background with 0, not 100. You might be able to work with that. SelectComponents[mat, "Label", MemberQ[keep, #] &] but this is a bit faster: sel = Compile[{{label, _Integer}, {keep, _Integer, 1}}, If[MemberQ[keep, label], label, 0], (* or 100 if necessary *) RuntimeAttributes -> {Listable}, ...


2

I just take the value of the pixel in the middle of the tile, if you want the mean value of the whole tile just use Mean@Flatten[ImageData[#], 1] & /@ p. s = Import["http://i.stack.imgur.com/ubuPp.jpg"]; p = Flatten[ImagePartition[s, {50, 69}], 1] colors = PixelValue[#, .5*ImageDimensions@#] & /@ p; GraphicsRow@{p[[1]], ...


2

It was stated in the comments to Vitaliy's answer that it would be tedious to rewrite it so that the colors of the regions correspond to the colors in the original image. For that reason I would like to supply a different way of "vectorizing" with a Voronoi diagram, which is quite straightforward. For a set of sample points pts: ...


2

This separates out the color from the black and white, and then subtracts the two. The final step of binarization returns it to (mostly) a line drawing. girl = Import["http://imgur.com/Q5ReXSX.jpg"]; girlP = ColorNegate@ ImageAdjust@ImageDifference[girl, (ColorSeparate@girl)[[3]]]; girl2 = ColorNegate@ImageAdjust@ImageSubtract[girlP, girl]; ...



Only top voted, non community-wiki answers of a minimum length are eligible