Hot answers tagged

17

Load image img = Import["http://i.stack.imgur.com/qzMGE.jpg"] ImagePartition and DominantColors Make an array of Disk of the DominantColors in each part of ImagePartition. Rotate[ Graphics@MapIndexed[ {First@DominantColors[#1, 1], Disk[#2, 1/2]} & , ImagePartition[img, 10], {2} ] , -π/2] ImageResize and ImageData But I find the ...


13

Just to make a functional form of nikie's answer, which can't be marked as a duplicate as it's on another SE site, improve[img_] := ImageCrop@ Binarize@Image[ ImageData[img]/ImageData[Closing[img, DiskMatrix[5]]]] improve@Import["http://i.stack.imgur.com/vWX65.jpg"]


12

My high-level strategy would be to use WatershedSegmentation on a gradient image (see this answer for a description of what this function does), starting from a marker image that looks like this: So WatershedSegmentation can grow the highlighted "seeds" until they touch at the highest gradient border. So first step: Get the marker image. It doesn't have ...


12

Here's my solution. Change CompilationTarget -> "C" to CompilationTarget -> "WVM" if you don't have a C compiler available. cf = Compile[{{v, _Real}, {kernel, _Real, 2}}, v*kernel, RuntimeAttributes -> {Listable}, Parallelization -> True, CompilationTarget -> "C", RuntimeOptions -> "Speed" ]; shapedPixels[img_, kernel_] ...


12

Another approach: pic = Import@"http://i.stack.imgur.com/qzMGE.jpg" Image @ ArrayFlatten @ Map[ Map[Function[x, x #], DiskMatrix[5], {2}]&, ImageData@ImageResize[pic, {Automatic, 50}], {2} ] I'm not taking care about preserving image size, it is governed by Resize and DiskMatrix size. just put e.g. DiamondMatrix[5] or ...


11

You need to: Rescale the image to a smaller size, ImageResize Extract the pixel values, ImageData Convert the triplets to RGBColor directive, and build a Graphics with appropriately coloured Disks inside. I found MapIndexed convenient for this. Code: img = ExampleData[{"TestImage", "Sailboat"}]; pixels = Transpose@ImageData[ImageResize[img, 50], ...


11

One approach is to smooth the image (here I've used the curvature flow filter, which is a nonlinear edge-preserving smoothing filter) and then binarize before doing the edge detection. img = Import["http://i.stack.imgur.com/TIiTZ.jpg"] curve = CurvatureFlowFilter[img, 40]; EdgeDetect[FillingTransform[DeleteSmallComponents[Binarize[curve]]]] Dilating ...


10

I think it's possible to find the shape automatically, but I can't say how reliable this will be. If you can post more sample images, I can try to improve this. Using your image: img = Import["http://i.stack.imgur.com/kL6cd.jpg"]; I would use watershed segmentation to find the particle. The idea is this: Imagine the image gradient strength as a 3d ...


8

I have a method that's more accurate, but I'm not sure how robust it is in the end. But maybe some of my tricks are useful for you. My first step to make the problem easier is to try to remove the perspective. If the pipes are all (more or less) vertical lines in the image, I can use image processing filters with anisotropic filter sizes, i.e. filters that ...


8

edit (30 Jan 2016) : one error corrected, rotation (§4) added,result slightly higher (1.3%) I propose the following solution : 1) interactively mark the frontier of the object by points 2) interactively mark the center of the object 3) use polar coordinates (r,theta) with the origin at the center. Thus r[theta] is symetric around a angle theta0, ...


8

If you evaluate Max[ImageData[pic]] with the image in the documentation, you get 13, i.e. the values of the white pixels are larger than 1, namely the disk radii in pixels. I'm guessing your image contains values between 0 and 1, so InverseDistanceTransform creates disks with radii between 0 and 1


7

The following seems to work at least for small grayscale images and a few points. My current computing power doesn't allow me to test it for larger examples. As this question was posed more than three years ago I decided to post this, despite the fact that I don't know how it scales. It makes a Voronoi partition and minimizes the Variance of the region ...


6

This is what I'd do: You say most of the pixels are dark, and thus uninteresting, but some of them are bright. So I'd start by summing all images up to find the "bad" pixels: files = FileNames[ "*.png"]; totalBrightness = 0.0; Monitor[Do[ totalBrightness = ImageData[Import[f]] + totalBrightness, {f, files}], f]; meanBrightness = ...


6

If you specify the size of the padding around the plot explicitly, calculating the right size for the plot is simple: piecePlot[piece_] := Module[{mat, padding = 20, gridSize = 30}, mat = StringCases[StringSplit[piece, ","], {"X" -> 1, "." -> 0}]; MatrixPlot[mat, Mesh -> All, FrameStyle -> Opacity[0], FrameTicksStyle -> Opacity[1], ...


6

The following is approx 30 times faster: (imageData = Flatten@ImageData@image; mean = Mean@imageData; nonzeroPixels = Total@Unitize@imageData; zeroPixels = Length@imageData - nonzeroPixels; stdDeviation = StandardDeviation@imageData) // Timing


6

If the problem is only to remove the grid, that's relatively easy. You just remove everything but the grid, then take the difference. You can use Closing with a rectangular structuring element to remove everything but the horizontal / vertical grid lines, like this: img = Import["http://i.stack.imgur.com/TkvSR.png"]; hFilter = Closing[img, ...


6

Here is an answer from the Wolfram Technical Support: Mathematica does not currently allow for an option for a logarithmic scale in ImageHistogram. However, taking apart the underlying structure, it is possible to rescale the data. The underlying structure is a GraphicsComplex, such that the following code should get you started on a workaround ...


5

If a grayscale image is needed, we can do as in Jason answer but replacing the binarize with an ImageAdjust. src = ColorConvert[Import@"http://i.stack.imgur.com/vWX65.jpg", "Grayscale"]; white = Closing[src, DiskMatrix[5]]; imgWithUniformBkg = Image[ImageData[src]/ImageData[white]]; ImageAdjust@imgWithUniformBkg But this results in an image that is too ...


5

Separating the lines can be done using DominantColors. The following is almost a straight copy from the documentation: res = DominantColors[img, 25, {"CoverageImage", "Color"}] Multicolumn[ImageMultiply @@@ res, Appearance -> "Horizontal"] After this (and perhaps after using somewhat more dominant colors, 50 or so, and playing with the ...


5

The code in this answer implements a 2D version of the approach in the question. It is fairly fast but does not have great precision. The achieved precision might be seen as good enough. Get image data (as in the set up of the answer by Dr. belisarius): ed = ExampleData /@ ExampleData["AerialImage"][[1 ;; 5]]; imgs = ColorConvert[ImageResize[#, 500], ...


4

The data FileNames["*.png"] (* {"image_01.png", "image_02.png", "image_03.png", \ "image_04.png", "image_05.png", "image_06.png", "image_07.png", \ "image_08.png", "image_09.png", "image_10.png"} *) All at once If there are no memory constraints, you can load all in a single array (read below for other cases). data = ImageData[Import[#], "Byte"] & ...


4

Do not use Rasterize for this! By default Rasterize will create a Graphics object that shows how some notebook element would display on-screen. This means that precision is bad and you risk introducing artefacts due to rounding errors (such as a one pixel margin, etc.) The result may depend on your operating system, on screen DPI settings and other things ...


4

To answer your question "how can I control the parameter to attach the texture to the ring?" - well it takes a bit of trial and error. There is some documentation on the TextureCoordinateFunction, and we can work the rest out ourselves. We want the horizontal and vertical directions of the image to go with the z axis and the angular coordinate. These ...


3

I'm not sure that I fully understand what you need, but perhaps the following will help you get started. First, import the picture: img = Import["http://vignette4.wikia.nocookie.net/rickandmorty/images/d/dd/Rick.png/revision/latest?cb=20131230003659"] Then find the outer edge: edge = EdgeDetect@ColorQuantize[img, 1] Finally, find the position of ...


3

I changed your image processing code a bit, by removing the unnecessary DeleteSmallComponents and removing the white lines using Closing. I also added a line to detect the pixel above the center. img = Import["http://i.stack.imgur.com/nQmQI.png"]; edge = MorphologicalPerimeter[Closing[ColorNegate@img, DiskMatrix[1]]]; coordinatescontour = ...


2

Trying to improve on my comment: The test image: img=Import["http://i.stack.imgur.com/psg1h.png"] Since Dilation... dil = Dilation[img, DiskMatrix[4]] ...can also be written as: fil = ImageFilter[Max[DiskMatrix[4] #] &, img, 4] ImageData[dil] == ImageData[fil] (* True *) this probably means that a non-binaray Dilation can be written as: ...


2

ImageApplyIndexed passes an index to your function, not X/Y coordinates, i.e. a list containing the row index and the column index (in that order). So you need to you Norm[{height/2, width/2} - pos. Because height is the number of rows, and width is the number of columns.


2

For the first tombstone the "image processing technique" needed is called "zoom" :) By zooming the image you can read quite clearly: Elizabeth P. Wife of W.H. Gray Died Jan 21, 1880 Aged 30 Yrs. 11 Mo. & 21 D's.


2

It seems like a nuisance coming from the interpolation used by ImageForwardTransformation when you use negative values of rpy[[2]]. The image looks grainy but overall OK without interpolation: ImageForwardTransformation[mwpic, changeEcliptic[##, {0 Degree, -40 Degree, 00 Degree}] &, 640, PlotRange -> {{-π, π}, {0, π}}, DataRange -> {{-π, π}, ...


1

EntropyFilter seems useful on the first image. img = Import["http://i.stack.imgur.com/8GnOn.jpg"]; EntropyFilter[img, 11] // ImageAdjust



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