New answers tagged

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


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 = ...


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"] & ...


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 ...


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"]


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, ...


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 ...


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: ...


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 = ...


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


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 ...


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 ...


9

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

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, ...


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 ...


0

Thank you very much to Scabolcs and rhermans. I have used ImageHistogram together with ParallelTable. For 10 images the improved code needs on my computer 2.51 sec (AbsoluteTiming) whereby the old code needed 124.22 sec. The speed is improved to a factor of about 50 ... great ... The only small but important difference is: I need a logarithmic y scale for ...


1

If your original image is image1 and your mask is maskimage then you can do the following: newImage = ImageMultiply[image1, maskimage]; newimage contains only the interesting gray level pixels where your maskimage is white.


1

Try to avoid Table where you can and use vectorized expressions instead. For example, if you create 2d arrays for x and y-coordinates: dims = {500, 500}; center = {100, 100}; ys = Array[N[#1] &, dims] - center[[1]]; xs = Array[N[#2] &, dims] - center[[2]]; you can then use xs and ys in expressions, and Sqrt, ArcTan and friends will automatically ...


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.


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], ...



Top 50 recent answers are included