Straighten curved image and measure the dark phase fraction

I would like to measure the dark phase fraction along the length of the curved path in image below

I thought the most straightforward way would be to straighten the curved path and then measure the area fraction of the dark phase along the length.

Can anyone suggest a way to straighten the path or any other strategy?
thank you for the help in advance :slight_smile:

1 Like

Hey Manoj,

Perhaps it is not necessary to warp your image, but to use instead the built-in capability of ImageJ to plot/measure the image values along a curved path. Something similar to what I tried below, use a segmented line, set the line thickness to cover the structure and then use Plot Profile. This seems to give you an averaged grey value along the “ribbon” where black=0 and white=255. Note that you need to double click the segmented line tool to set the line thickness. A sample macro is below the screenshot. Hope you can tweak this approach to work for you.

Regards, David

run("8-bit");
makeLine(1647,969,1677,969,1707,969,1738,969,1768,969,1799,969,1829,969,1859,969,1890,969,1920,969,1950,969,1980,969,2010,969,2040,969,2070,969,2100,969,2129,970,2159,970,2188,970,2217,970,2246,970,2275,970,2304,970,2333,970,2361,970,2390,970,2418,970,2446,970,2473,970,2501,970,2528,970,2555,971,2582,971,2609,971,2635,971,2661,971,2687,971,2713,971,2738,971,2763,971,2788,971,2813,971,2837,971,2861,971,2884,971,2908,972,2931,972,2953,972,2976,972,2997,972,3019,972,3040,972,3061,972,3082,972,3102,972,3121,972,3141,972,3159,972,3178,973,3196,973,3214,973,3231,973,3247,973,3264,973,3280,973,3295,973,3310,973,3324,973,3338,973,3352,973,3364,974,3377,974,3389,974,3400,974,3411,974,3421,974,3431,974,3440,974,3449,974,3457,974,3464,974,3471,975,3478,975,3484,975,3489,975,3494,975,3499,975,3503,976,3507,976,3511,976,3515,977,3519,977,3522,978,3526,978,3529,979,3533,980,3537,981,3540,982,3544,983,3549,984,3553,985,3557,987,3562,988,3566,990,3571,992,3575,994,3580,996,3585,998,3590,1000,3594,1003,3599,1006,3604,1009,3608,1012,3613,1015,3617,1019,3622,1022,3626,1026,3631,1030,3635,1035,3639,1039,3643,1043,3647,1048,3651,1053,3655,1058,3659,1063,3663,1068,3666,1074,3670,1079,3674,1085,3677,1090,3681,1096,3684,1102,3687,1108,3690,1114,3693,1120,3696,1126,3699,1132,3702,1139,3705,1145,3708,1151,3710,1158,3713,1164,3715,1171,3718,1178,3720,1184,3722,1191,3724,1198,3726,1205,3728,1212,3730,1219,3731,1226,3733,1233,3734,1240,3735,1247,3736,1254,3737,1261,3738,1269,3739,1276,3740,1284,3740,1291,3740,1298,3741,1306,3741,1314,3740,1321,3740,1329,3740,1337,3739,1344,3738,1352,3738,1360,3737,1367,3735,1375,3734,1383,3733,1390,3731,1398,3730,1405,3728,1412,3726,1420,3724,1427,3722,1434,3720,1441,3717,1448,3715,1455,3712,1461,3710,1468,3707,1474,3704,1480,3701,1486,3698,1492,3694,1498,3691,1503,3688,1509,3684,1514,3680,1519,3677,1524,3673,1528,3669,1533,3665,1537,3660,1541,3656,1546,3652,1550,3647,1553,3643,1557,3638,1561,3633,1564,3628,1568,3623,1571,3618,1575,3613,1578,3608,1581,3603,1584,3597,1587,3592,1590,3586,1593,3580,1595,3575,1598,3569,1600,3563,1603,3557,1605,3552,1607,3546,1609,3540,1611,3535,1613,3529,1615,3524,1616,3518,1618,3513,1619,3507,1620,3502,1621,3497,1622,3492,1623,3488,1623,3483,1624,3478,1624,3474,1624,3469,1624,3465,1624,3460,1624,3455,1624,3450,1623,3445,1623,3439,1622,3433,1622,3427,1621,3421,1621,3414,1620,3407,1620,3400,1619,3391,1618,3383,1618,3374,1617,3364,1617,3354,1616,3343,1616,3331,1615,3319,1615,3306,1615,3293,1614,3279,1614,3265,1614,3250,1614,3235,1614,3220,1613,3204,1613,3187,1613,3171,1613,3153,1613,3136,1613,3118,1614,3101,1614,3082,1614,3064,1614,3045,1614,3026,1614,3007,1614,2988,1615,2969,1615,2950,1615,2930,1615,2911,1616,2891,1616,2872,1616,2852,1617,2833,1617,2813,1617,2794,1617,2774,1618,2755,1618,2736,1618,2717,1619,2698,1619,2680,1619,2661,1620,2643,1620,2625,1620,2607,1621,2590,1621,2573,1621,2556,1621,2540,1621,2524,1622,2509,1622,2494,1622,2479,1622,2465,1622,2451,1622,2438,1622,2425,1623,2413,1623,2402,1623,2391,1622,2380,1622,2371,1622,2361,1622,2353,1622,2345,1622,2337,1622,2329,1621,2322,1621,2316,1621,2310,1621,2304,1620,2298,1620,2293,1620,2288,1619,2283,1619,2278,1619,2274,1618,2269,1618,2265,1618,2261,1617,2257,1617,2253,1617);
run("Plot Profile");
1 Like

I agree with @david.bragason but if you really need to warp your image, I face a similar problem with aerial images of meandering channels.

First you have to define a continuous path in the middle of your channels. In your case, I used some straight lines and partial circumferences. Then you can unwrap your image using a linear map running along the path.

I attach the (uncommented) scripts I used. You will need Perl and ImageMagick.

perl path.pl > path.txt
magick convert phase.png -compress none phase.ppm
perl remap.pl
magick convert out.ppm -rotate -90 straight.png

straight.zip (266.6 KB)

1 Like

If you want to unwrap your image, there is no need for external tools, as ImageJ/Fiji already has this capability. Use the Edit > Selection > Straighten command. Below is an example macro that straightens a segment of the image:

run("8-bit");
makeLine(2946,960,3462,960,3606,1020,3702,1128,3732,1260,3738,1368,3660,1524,3492,1632,3204,1626,3078,1614);
run("Straighten...");

2 Likes

Hi David,
That looks like a good solution for my need.
Thank you very much for quick reply.
Cheers
Manoj

This is really good. I never used Perl and ImageMagick before. I will give it a try. Thank you very much

I tried inbuilt straighten and the straighten plugin but I couldn’t get good results for whole length.

I have simplified my path to 120 points so you can test to straight the whole image in ImageJ/Fiji .

run("8-bit");
makeLine(1698,295,649,295,599,297,550,305,502,321,458,343,417,372,381,406,350,446,326,490,308,536,297,585,294,635,298,685,310,733,328,780,353,823,385,862,421,896,463,924,508,946,556,960,605,968,655,969,3355,969,3405,969,3455,974,3503,987,3549,1006,3591,1033,3630,1065,3662,1103,3689,1145,3709,1191,3722,1239,3728,1289,3726,1338,3717,1387,3700,1435,3676,1479,3647,1519,3611,1554,3571,1583,3526,1606,3479,1622,3430,1631,3380,1633,680,1633,630,1633,580,1637,532,1648,485,1667,442,1692,403,1724,370,1761,342,1802,321,1848,307,1895,300,1945,301,1995,309,2044,325,2092,347,2136,377,2177,411,2213,451,2243,495,2267,542,2284,591,2294,641,2296,3391,2296,3441,2299,3490,2310,3536,2328,3580,2353,3619,2384,3653,2421,3680,2462,3702,2507,3716,2555,3723,2605,3722,2654,3714,2704,3698,2751,3675,2796,3646,2836,3611,2872,3571,2902,3527,2925,3480,2942,3431,2951,3381,2953,631,2953,581,2957,532,2968,486,2986,443,3011,403,3042,369,3079,341,3120,319,3165,305,3213,297,3262,297,3312,304,3361,319,3409,340,3454,368,3496,402,3533,441,3564,484,3589,531,3608,579,3619,629,3623,679,3623,2029,3623,2078,3632,2110,3668,2115,3718,2115,4412);
run("Straighten...");

The path is changing automatically when I run straighten command.

Try this path with points inside the straight lines:

makeLine(1698,295,1599,295,1549,295,1499,295,1449,295,1399,295,1349,295,1299,295,1249,295,1199,295,1149,295,1099,295,1049,295,999,295,949,295,899,295,849,295,799,295,749,295,699,295,649,295,599,297,550,305,502,321,458,343,417,372,381,406,350,446,326,490,308,536,297,585,294,635,298,685,310,733,328,780,353,823,385,862,421,896,463,924,508,946,556,960,605,968,655,969,705,969,755,969,805,969,855,969,905,969,955,969,1005,969,1055,969,1105,969,1155,969,1205,969,1255,969,1305,969,1355,969,1405,969,1455,969,1505,969,1555,969,1605,969,1655,969,1705,969,1755,969,1805,969,1855,969,1905,969,1955,969,2005,969,2055,969,2105,969,2155,969,2205,969,2255,969,2305,969,2355,969,2405,969,2455,969,2505,969,2555,969,2605,969,2655,969,2705,969,2755,969,2805,969,2855,969,2905,969,2955,969,3005,969,3055,969,3105,969,3155,969,3205,969,3255,969,3305,969,3355,969,3405,969,3455,974,3503,987,3549,1006,3591,1033,3630,1065,3662,1103,3689,1145,3709,1191,3722,1239,3728,1289,3726,1338,3717,1387,3700,1435,3676,1479,3647,1519,3611,1554,3571,1583,3526,1606,3479,1622,3430,1631,3380,1633,3330,1633,3280,1633,3230,1633,3180,1633,3130,1633,3080,1633,3030,1633,2980,1633,2930,1633,2880,1633,2830,1633,2780,1633,2730,1633,2680,1633,2630,1633,2580,1633,2530,1633,2480,1633,2430,1633,2380,1633,2330,1633,2280,1633,2230,1633,2180,1633,2130,1633,2080,1633,2030,1633,1980,1633,1930,1633,1880,1633,1830,1633,1780,1633,1730,1633,1680,1633,1630,1633,1580,1633,1530,1633,1480,1633,1430,1633,1380,1633,1330,1633,1280,1633,1230,1633,1180,1633,1130,1633,1080,1633,1030,1633,980,1633,930,1633,880,1633,830,1633,780,1633,730,1633,680,1633,630,1633,580,1637,532,1648,485,1667,442,1692,403,1724,370,1761,342,1802,321,1848,307,1895,300,1945,301,1995,309,2044,325,2092,347,2136,377,2177,411,2213,451,2243,495,2267,542,2284,591,2294,641,2296,691,2296,741,2296,791,2296,841,2296,891,2296,941,2296,991,2296,1041,2296,1091,2296,1141,2296,1191,2296,1241,2296,1291,2296,1341,2296,1391,2296,1441,2296,1491,2296,1541,2296,1591,2296,1641,2296,1691,2296,1741,2296,1791,2296,1841,2296,1891,2296,1941,2296,1991,2296,2041,2296,2091,2296,2141,2296,2191,2296,2241,2296,2291,2296,2341,2296,2391,2296,2441,2296,2491,2296,2541,2296,2591,2296,2641,2296,2691,2296,2741,2296,2791,2296,2841,2296,2891,2296,2941,2296,2991,2296,3041,2296,3091,2296,3141,2296,3191,2296,3241,2296,3291,2296,3341,2296,3391,2296,3441,2299,3490,2310,3536,2328,3580,2353,3619,2384,3653,2421,3680,2462,3702,2507,3716,2555,3723,2605,3722,2654,3714,2704,3698,2751,3675,2796,3646,2836,3611,2872,3571,2902,3527,2925,3480,2942,3431,2951,3381,2953,3331,2953,3281,2953,3231,2953,3181,2953,3131,2953,3081,2953,3031,2953,2981,2953,2931,2953,2881,2953,2831,2953,2781,2953,2731,2953,2681,2953,2631,2953,2581,2953,2531,2953,2481,2953,2431,2953,2381,2953,2331,2953,2281,2953,2231,2953,2181,2953,2131,2953,2081,2953,2031,2953,1981,2953,1931,2953,1881,2953,1831,2953,1781,2953,1731,2953,1681,2953,1631,2953,1581,2953,1531,2953,1481,2953,1431,2953,1381,2953,1331,2953,1281,2953,1231,2953,1181,2953,1131,2953,1081,2953,1031,2953,981,2953,931,2953,881,2953,831,2953,781,2953,731,2953,681,2953,631,2953,581,2957,532,2968,486,2986,443,3011,403,3042,369,3079,341,3120,319,3165,305,3213,297,3262,297,3312,304,3361,319,3409,340,3454,368,3496,402,3533,441,3564,484,3589,531,3608,579,3619,629,3623,679,3623,729,3623,779,3623,829,3623,879,3623,929,3623,979,3623,1029,3623,1079,3623,1129,3623,1179,3623,1229,3623,1279,3623,1329,3623,1379,3623,1429,3623,1479,3623,1529,3623,1579,3623,1629,3623,1679,3623,1729,3623,1779,3623,1829,3623,1879,3623,1929,3623,1979,3623,2029,3623,2078,3632,2110,3668,2115,3718,2115,3768,2115,3818,2115,3868,2115,3918,2115,3968,2115,4018,2115,4068,2115,4118,2115,4168,2115,4218,2115,4268,2115,4318,2115,4412);

thank you :slight_smile: that worked. how did you draw the line?

I computed mathematically the path by joining the straight lines along the center of the channels with semi-circumferences. The details of the parametric equations can bee seen in the previously attached Perl script.

cool, thank you once again :slight_smile: