IDL code for minimum distance calculationNot sure if I missed some obvious CPU brakesK-nearest neighbours in...

page split between longtable caption and table

Could flying insects re-enter the Earth's atmosphere from space without burning up?

Does Windows 10's telemetry include sending *.doc files if Word crashed?

What to do if authors don't respond to my serious concerns about their paper?

Everyone is beautiful

What is the etymology of the kanji 食?

Can you earn endless XP using a Flameskull and its self-revival feature?

How experienced do I need to be to go on a photography workshop?

Getting a UK passport renewed when you have dual nationality and a different name in your second country?

How did the original light saber work?

Retractions in mathematical journals

QGIS: use geometry from different layer in symbology expression

Unwarranted claim of higher degree of accuracy in zircon geochronology

What's the most convenient time of year in the USA to end the world?

integral inequality of length of curve

Can I become debt free or should I file for bankruptcy? How do I manage my debt and finances?

Knowing when to use pictures over words

If I delete my router's history can my ISP still provide it to my parents?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Quenching swords in dragon blood; why?

What kind of hardware implements Fourier transform?

Overfitting and Underfitting

Does the "particle exchange" operator have any validity?

How to avoid being sexist when trying to employ someone to function in a very sexist environment?



IDL code for minimum distance calculation


Not sure if I missed some obvious CPU brakesK-nearest neighbours in C# for large number of dimensionsParsing and plotting complex numbersSimple multi-dimensional Array class in C++11Pixelating black and white imagesIterating over thousands of objects to generate htmlInterpolating data of multiple trainsRetrieving website categories from a three-level hierarchyGenerating code combinations for matching conditionsdqueue - A dynamic FIFO queue library for C













3












$begingroup$


I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like:



function minimum_distance, stack, exercising_data

;variables
nbands = get_number_of_bands()
nclasses = get_number_of_classes()
x_size = (size(stack, /DIMENSIONS))[0]
y_size = (size(stack, /DIMENSIONS))[1]
result = MAKE_ARRAY(x_size,y_size,/INTEGER)

;calculate class mean for each class
class_means = calculate_class_means(exercising_data)

;find closest class mean for each point and create result image
i = 0
foreach point, stack[0,*,0], i do begin
foreach point, stack[*,i,0], j do begin
print, string(i) + "-" + string(j)
point = REFORM(stack[j,i,*],7,1)
dist_array = [[point],[class_means]]
class = (DISTANCE_MEASURE(dist_array))[0:nclasses-1]
class = min(class,location)
result[j,i] = location
end
end

;prepare result for display
result = result * (255/(nclasses-1))
result = REVERSE(ROTATE(result,2))

return, result

end


The stack is an array of tif files of Landsat 7 data that I load with the read_tiff function. The exercising data looks like this:



;Forst
[ $
[39,25,21,29,14,80,12], $
[40,25,20,28,11,79,12], $
[37,24,20,29,14,81,11], $
[43,28,25,34,14,79,12], $
[44,29,29,40,13,79,13], $
[41,27,23,32,14,80,13], $
[0,0,0,0,0,0,0], $
[46,31,27,36,13,79,12] $
], $

... (more classes)

;Water
[ $
[39,24,19,13,9,92,10], $
[37,22,19,13,9,92,10], $
[38,24,20,13,9,90,10], $
[40,24,22,15,9,89,10], $
[37,22,19,13,10,92,9], $
[38,23,20,13,10,89,9], $
[37,23,18,13,9,90,9], $
[39,25,20,13,9,90,9] $
] $


The program actually works, but doesn't have a good performance. This is due to the nested foreach-loops within the minimum_distance function. With larger satellite images it takes a very long time to process. I can imagine that you can reach a much better performance using some IDL function that I don't know of. Do you know a way in how I can give this program a better performance and replace the foreach-loops?



If you want to take a look at the complete program, here it is.










share|improve this question











$endgroup$

















    3












    $begingroup$


    I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like:



    function minimum_distance, stack, exercising_data

    ;variables
    nbands = get_number_of_bands()
    nclasses = get_number_of_classes()
    x_size = (size(stack, /DIMENSIONS))[0]
    y_size = (size(stack, /DIMENSIONS))[1]
    result = MAKE_ARRAY(x_size,y_size,/INTEGER)

    ;calculate class mean for each class
    class_means = calculate_class_means(exercising_data)

    ;find closest class mean for each point and create result image
    i = 0
    foreach point, stack[0,*,0], i do begin
    foreach point, stack[*,i,0], j do begin
    print, string(i) + "-" + string(j)
    point = REFORM(stack[j,i,*],7,1)
    dist_array = [[point],[class_means]]
    class = (DISTANCE_MEASURE(dist_array))[0:nclasses-1]
    class = min(class,location)
    result[j,i] = location
    end
    end

    ;prepare result for display
    result = result * (255/(nclasses-1))
    result = REVERSE(ROTATE(result,2))

    return, result

    end


    The stack is an array of tif files of Landsat 7 data that I load with the read_tiff function. The exercising data looks like this:



    ;Forst
    [ $
    [39,25,21,29,14,80,12], $
    [40,25,20,28,11,79,12], $
    [37,24,20,29,14,81,11], $
    [43,28,25,34,14,79,12], $
    [44,29,29,40,13,79,13], $
    [41,27,23,32,14,80,13], $
    [0,0,0,0,0,0,0], $
    [46,31,27,36,13,79,12] $
    ], $

    ... (more classes)

    ;Water
    [ $
    [39,24,19,13,9,92,10], $
    [37,22,19,13,9,92,10], $
    [38,24,20,13,9,90,10], $
    [40,24,22,15,9,89,10], $
    [37,22,19,13,10,92,9], $
    [38,23,20,13,10,89,9], $
    [37,23,18,13,9,90,9], $
    [39,25,20,13,9,90,9] $
    ] $


    The program actually works, but doesn't have a good performance. This is due to the nested foreach-loops within the minimum_distance function. With larger satellite images it takes a very long time to process. I can imagine that you can reach a much better performance using some IDL function that I don't know of. Do you know a way in how I can give this program a better performance and replace the foreach-loops?



    If you want to take a look at the complete program, here it is.










    share|improve this question











    $endgroup$















      3












      3








      3





      $begingroup$


      I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like:



      function minimum_distance, stack, exercising_data

      ;variables
      nbands = get_number_of_bands()
      nclasses = get_number_of_classes()
      x_size = (size(stack, /DIMENSIONS))[0]
      y_size = (size(stack, /DIMENSIONS))[1]
      result = MAKE_ARRAY(x_size,y_size,/INTEGER)

      ;calculate class mean for each class
      class_means = calculate_class_means(exercising_data)

      ;find closest class mean for each point and create result image
      i = 0
      foreach point, stack[0,*,0], i do begin
      foreach point, stack[*,i,0], j do begin
      print, string(i) + "-" + string(j)
      point = REFORM(stack[j,i,*],7,1)
      dist_array = [[point],[class_means]]
      class = (DISTANCE_MEASURE(dist_array))[0:nclasses-1]
      class = min(class,location)
      result[j,i] = location
      end
      end

      ;prepare result for display
      result = result * (255/(nclasses-1))
      result = REVERSE(ROTATE(result,2))

      return, result

      end


      The stack is an array of tif files of Landsat 7 data that I load with the read_tiff function. The exercising data looks like this:



      ;Forst
      [ $
      [39,25,21,29,14,80,12], $
      [40,25,20,28,11,79,12], $
      [37,24,20,29,14,81,11], $
      [43,28,25,34,14,79,12], $
      [44,29,29,40,13,79,13], $
      [41,27,23,32,14,80,13], $
      [0,0,0,0,0,0,0], $
      [46,31,27,36,13,79,12] $
      ], $

      ... (more classes)

      ;Water
      [ $
      [39,24,19,13,9,92,10], $
      [37,22,19,13,9,92,10], $
      [38,24,20,13,9,90,10], $
      [40,24,22,15,9,89,10], $
      [37,22,19,13,10,92,9], $
      [38,23,20,13,10,89,9], $
      [37,23,18,13,9,90,9], $
      [39,25,20,13,9,90,9] $
      ] $


      The program actually works, but doesn't have a good performance. This is due to the nested foreach-loops within the minimum_distance function. With larger satellite images it takes a very long time to process. I can imagine that you can reach a much better performance using some IDL function that I don't know of. Do you know a way in how I can give this program a better performance and replace the foreach-loops?



      If you want to take a look at the complete program, here it is.










      share|improve this question











      $endgroup$




      I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like:



      function minimum_distance, stack, exercising_data

      ;variables
      nbands = get_number_of_bands()
      nclasses = get_number_of_classes()
      x_size = (size(stack, /DIMENSIONS))[0]
      y_size = (size(stack, /DIMENSIONS))[1]
      result = MAKE_ARRAY(x_size,y_size,/INTEGER)

      ;calculate class mean for each class
      class_means = calculate_class_means(exercising_data)

      ;find closest class mean for each point and create result image
      i = 0
      foreach point, stack[0,*,0], i do begin
      foreach point, stack[*,i,0], j do begin
      print, string(i) + "-" + string(j)
      point = REFORM(stack[j,i,*],7,1)
      dist_array = [[point],[class_means]]
      class = (DISTANCE_MEASURE(dist_array))[0:nclasses-1]
      class = min(class,location)
      result[j,i] = location
      end
      end

      ;prepare result for display
      result = result * (255/(nclasses-1))
      result = REVERSE(ROTATE(result,2))

      return, result

      end


      The stack is an array of tif files of Landsat 7 data that I load with the read_tiff function. The exercising data looks like this:



      ;Forst
      [ $
      [39,25,21,29,14,80,12], $
      [40,25,20,28,11,79,12], $
      [37,24,20,29,14,81,11], $
      [43,28,25,34,14,79,12], $
      [44,29,29,40,13,79,13], $
      [41,27,23,32,14,80,13], $
      [0,0,0,0,0,0,0], $
      [46,31,27,36,13,79,12] $
      ], $

      ... (more classes)

      ;Water
      [ $
      [39,24,19,13,9,92,10], $
      [37,22,19,13,9,92,10], $
      [38,24,20,13,9,90,10], $
      [40,24,22,15,9,89,10], $
      [37,22,19,13,10,92,9], $
      [38,23,20,13,10,89,9], $
      [37,23,18,13,9,90,9], $
      [39,25,20,13,9,90,9] $
      ] $


      The program actually works, but doesn't have a good performance. This is due to the nested foreach-loops within the minimum_distance function. With larger satellite images it takes a very long time to process. I can imagine that you can reach a much better performance using some IDL function that I don't know of. Do you know a way in how I can give this program a better performance and replace the foreach-loops?



      If you want to take a look at the complete program, here it is.







      performance iteration interactive-data-language






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 12 mins ago









      Jamal

      30.3k11119227




      30.3k11119227










      asked Jan 29 at 10:18









      TheKidsWantDjentTheKidsWantDjent

      1161




      1161






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212458%2fidl-code-for-minimum-distance-calculation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212458%2fidl-code-for-minimum-distance-calculation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...