I’m using ImageJ for crack detection and, to test my workflow, I uploded an image with known widths that I created in AutoCAD.
The cracks width varies from 0.3 mm to 2 cm, and, after processing this image, I saved it as a text file, but all the width values I get are from 0 mm to 2 cm. Is it possible to change it in some way to obtain values less than zero? If I manually measure the crack from ImageJ, I get, for example, 0.4 mm, but not if I use the matrix.
Many thanks for considering my request.
Please provide, in TIFF format, an image you are trying to save as a text file.
Hi, this is the image I was talking about.
Crepa cad 1.tif (2.5 MB)
Dear Eugenia, to me it looks like as if the TIFF image that you provided contains the crack before processing. The way you describe your issue, there seems to be some processing done that creates a new image that contains values corresponding to the crack width. Could you share with us this processed image as well?
I’m sorry that I provided the wrong image. The right one is below with its txt format.
I obtained the “Result of distance map.tif” by multiplying the image distance map and skeleton.
Thanks! I had a look at the distance map TIFF image and I only find 0 and 255 as values in there.
Using the pixel inspection tool:
Could you confirm? Maybe it is still the wrong image?
since I was involved in one of your previous posts regarding the measurement of crack width I will jump in here.
Here is a macro what creates skeleton, distance map and the multiplication of both. I assume your macro or manual processing is close to similar.
// Macro: CrackWidth.ijm title = getTitle(); //Dublicate the original image 2x run("Duplicate...", "title=DistanceMap"); selectWindow(title); run("Duplicate...", "title=Skeleton"); // Create the Skeleton and make it binary 0|1 selectWindow("Skeleton"); setOption("BlackBackground", true); run("Skeletonize"); run("Divide...", "value=255.0"); // Create the distance map selectWindow("DistanceMap"); run("Distance Map"); // Multiply skeleton and distance map imageCalculator("Multiply create", "DistanceMap","Skeleton"); selectWindow("Result of DistanceMap"); // Improve visual contrast //run("Enhance Contrast", "saturated=0.001"); setMinAndMax(0, 8); run("Fire");
The image from your original (Crepa cad 1.tif) should look like that:
The problem was (and is) the selection in your image.
Because of the selection the command
run("Divide...", "value=255.0"); is not applied to the skeleton image and as a consequence you get a wrong multilication.
@Wayne Maybe you should look into this issue if this is not the intended behaviour.
So, simple solution for you, Eugenia:
Just remove the selection.
Then you will see a correct text image and correct histogram values (as described in your last post).
Hope that helps.
Hi @phaub, and thank you again for helping me!
I tried what you said, and the pixel values are no longer 255. Still, I can’t get values like 0.4 but only 0 mm.
@Christian_Tischer Sorry again if I wasted your time, I’ve just uploaded the new one obtained by @phaub suggestions, and I guess it is right now. My only issue is now how get values like 0.4, 0.5 mm because I only get 0.
Forgive me, I have expressed myself badly here. I meant values above zero such as 0.1, 0.2, etc. because I only get integer numbers.
the discussed approach to measure the crack width is based on EDM (Euclidian Distance Map) which uses 8bit data. The distance values are given as integer values without decimals.
This approach can not deliver results other than 0, 1, 2 etc.
A solution could be to increase the size of your image with an appropriate interpolation and an appropriate scaling factor.
After measuring the ‘crack width’ in this resized image you can calculate the ‘width’ in the original scale by divinding the resuling values by the scale factor used to increase the image size.
Thank you for the explanation and sorry again for the inconvenience!
The “Divide…” command, and the other commands in the Process>Math menu, limit processing to the selection. To always process the entire image, add
to the beginning of the macro.
To create a Euclidian Distance Map that uses 32-bit float values use
run("Options...", "black edm=32-bit"); run("Distance Map");
Thanks @Wayne for this clarification.
I have overlooked that the selection in the original image (Crepa cad 1.tif) was ‘inverted’. The part of the image outside the crack was selected.
Also thanks for this important hint.
@Eugenia_Falvo Here is a version including the modifications proposed by Wayne:
title = getTitle(); run("Select None"); // Create the Skeleton and make it binary 0|1 run("Duplicate...", "title=Skeleton"); setOption("BlackBackground", true); run("Skeletonize"); run("Divide...", "value=255.0"); // Create the distance map run("Options...", "black edm=32-bit") selectWindow(title); run("Distance Map"); rename("EDM"); // Multiply skeleton and distance map imageCalculator("Multiply create", "EDM","Skeleton"); rename("EDM_*_Skeleton"); // Improve visual contrast setMinAndMax(0, 8); run("Fire");
Please have in mind that even if the distance map is created with 32-bit accuracy the distances between pixels are not measured with subpixel accuracy but only in steps of the pixel grid. That means that the smallest distance that can be measured is 1.
If you want your measurements given in spatial units (i.e. mm) you can use the spatial calibration to transform the results from distance map, given in ‘units’ of the pixel grid, into spatial units.
I’ll try what you suggested!