TransWikia.com

Mathematica 12.1 trial version, very slow to evaluate a property in multiple pictures

Mathematica Asked by Hussain-Alqatari on June 28, 2021

I am a new mathematica user.

I am using the following code to measure the internal rectangle width in some images. When I run mathematica for $1$ image, it takes a short time. Also, it works and it shows the results for more than one image. However, it takes (EXTREMELY) long time to show the results, especially when the number of picture more than $5$. It took around $25$ minutes to process around $35$ pictures!

One possibility, that my requirement from mathematica is too much, and it is normal to process $35$image/$25$min.

One possibility, that I use mathematica in a wrong way to get the result; I go to Evaluation bar then Evaluate Notebook option.

enter image description here

One possibility, that the code can be modified in a way it will work faster.

One possibility, that this version of mathematica (12.1) has an issue.

PLEASE CHECK THE FOLLOWING:

ClearAll[vDilate, internalRectangles, dataSet]

vDilate = 
  ColorNegate@
    Dilation[MorphologicalBinarize@#, 
     ConstantArray[1, {ImageDimensions[#][[1]], 1}]] &;

internalRectangles[w_ : 1] := 
  Rectangle @@@ 
    Values[ComponentMeasurements[
      SelectComponents[
       vDilate@#, #CaliperWidth > 
          w && #AdjacentBorders == {Bottom, Top} &], "BoundingBox"]] &;

dataSet[w_ : 1] := 
  ComponentMeasurements[
    SelectComponents[
     vDilate@#, #CaliperWidth > 
        w && #AdjacentBorders == {Bottom, Top} &], {"BoundingBox", 
     "CaliperWidth"}, "Dataset"] &;

{img1, img2, img3, img4, img5, img6} = 
 Import /@ {"D:SHARGAM167716 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) 
(61-65 C) 2 4046 08-03-12  10-06-2020.jpg", 
   "D:SHARGAM252929 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (75-80 
C) 2 4048 09-16-57  11-06-2020.jpg", 
   "D:SHARGAM232614 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (70-75 
C) 2 4051 03-15-54  11-06-2020.jpg", 
   "D:SHARGAM211778 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (70-75 
C) 2 4051 21-05-53  10-06-2020.jpg", 
   "D:SHARGAM192633 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (70-75 
C) 2 4052 15-25-53  10-06-2020.jpg", 
   "D:SHARGAM172707 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (65-70 
C) 2 4050 09-31-56  10-06-2020.jpg"}


ClearAll[dataSet2]
dataSet2 = 
  MaximalBy[#CaliperWidth &]@
    ComponentMeasurements[
     SelectComponents[
      vDilate@#, #AdjacentBorders == {Bottom, Top} &], {"BoundingBox",
       "CaliperWidth"}, "Dataset"] &;

dataSet2 /@ {img1, img2, img3, img4, img5, img6}

Where;

“D:SHARGAM167716 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (61-65 C) 2
4046 08-03-12 10-06-2020.jpg”, “D:SHARGAM252929 6 SDGM Comp 2
HRDH B2 4200 rpm + TB) (75-80 C) 2 4048 09-16-57 11-06-2020.jpg”,
“D:SHARGAM232614 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (70-75 C) 2
4051 03-15-54 11-06-2020.jpg”, “D:SHARGAM211778 6 SDGM Comp 2
HRDH B2 4200 rpm + TB) (70-75 C) 2 4051 21-05-53 10-06-2020.jpg”,
“D:SHARGAM192633 6 SDGM Comp 2 HRDH B2 4200 rpm + TB) (70-75 C) 2
4052 15-25-53 10-06-2020.jpg”, “D:SHARGAM172707 6 SDGM Comp 2
HRDH B2 4200 rpm + TB) (65-70 C) 2 4050 09-31-56 10-06-2020.jpg”

are the path of the images to be processed, they look like this;

enter image description here

It took around $3.5-4$ minutes for those $6$ images!


If I need to find the caliperwidth of $1000$ images, it may take $1000$ life-times!


You can see my previous problem, kglr helped a lot. Many thanks to kglr.


AGAIN, I am a new mathematica user. (2 days).


Any help/suggestion to modify the code, or correcting me on how to evaluate the outputs, would be really appreciated. THANKS!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP