Calculation of Euclidean distance faster

Hello

I tried to built a VI that computes a transformation of Euclidean distance on a 2D Image binary.

The VI looks like this:

So for each black pixel, it calculates the distance to each pixel of the other, and then selects the lowest distance.

And it works exactly as it should, the next entry produces the following output:

 

Just as it should be. However, it is extremely slow. It took about 340 seconds for this image of 512 x 512. In my view, that the runtime is O(n^4). I saw (in c) algorithms, that in o (n), but I don't know how to implement these in LabVIEW. Is there a simple but nice way to speed it up?

You can find the attached VI. Thanks in advance.


Tags: NI Software

Similar Questions

  • Calculation of the distance of the location GPS provider

    I'm looking to develop an application of GPS based location by saving a LocationListener with the LocationProvider, I need to be able to calculate the distance between two cooridinates.

    The Coordinates () .distance method doesn't seem to work, also responds to 0.

    I saw and distance example where speed and range were used to calculate, but I was wondering is this reliable?

    An alternative is to calculate the distance between two coordinates using the Haversine formula, the java class Math in Blackberry JDE however does not have the required operation atan2. Anyone know of any alternative?

    Thank you

    Dave

    In my experience, the distance calculation works.  What results are you seeing?  Are you sure these two places are valid?

    I would not use speed and interval unless there is no other choice, or that the interval was small.

    The quesiton on atan was invited to this forum, have a search for her.  Here is an answer:

    BB has no ACON, ATAN, ASIN

    http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&message.ID=142&query.ID=2195...

  • Euclidean distance?

    I know that to measure the distance between a set of points, the equation is SQRT ((x2-x1) ^ 2 + (y2 - y1) ^ 2)

    I want to double the length of a line a - b for a new line a - c. How can I solve for c? Is there something in vi.lib?

  • Vector3D.distance

    In AS3, I try to get the dstance between 2 3D objects using the method of distance.

    If (Vector3D.distance (Model.position, Model2.position) < 100)

    {

    do something

    }

    ..

    > > you can use it directly as a class method Vector3D to get the Euclidean distance between two points in three dimensions.

    How this method is looking for? It is the closest point on the other object?

    I don't do that think about how much time it would take in tests of the objects with number of large poly.

    It captures not point - it calculates the distance between two points.

  • What is the algorithm of outer glow 'soft '?

    I'm trying to implement some effects in C++ for my UI controls. I realized that the Layer Styles Photoshop uses a form of anti-aliasing of the transformation of Euclidean Distance for "Precise" (inner glow and outer glow) techniques.

    But what is the method used for the technique of 'Soft' outer glow and inner glow? It seems that this is also used for "Smooth" technique the computation of map of the height for bevel and Emboss.

    Pointers would be appreciated!

    Wow, thanks for all the help people. After a lot of risk of tearing of hair and some collaborations, I finally thought to it:

    (1) make an accounting on the areas that require compositing, based on the offset of the shadow, the morphological expansion and cutting to the destination.

    (2) expand the mask to grayscale using a metric of chamfer 5,7,11 (the original G. Borgefors algorithm is adapted). Output 8 bit fixed point.

    (3) apply the blur of the box.

    (4) apply to the 1 to 1 curved contour function, conversion to 8-bit alpha values in the range 0-255.

    (5) fill the destination image using the color of the drop shadow, calculated 8-bit alpha channel, blend mode and opacity effect.

    Thanks for nothing!

  • First HP: HP first and arc length

    The evaluation of integrals of arc length, I noticed that the first HP often fails to produce a result. The error message is usually some about "Something Talyor", so I guess that the calculations of the calculator do not converge fast enough. For example, I got an error trying to calculate the length of the arc of ln (cos (x)) for x = 0 to x = pi/4.

    Now, I had other integrals of arc length, in the past, who have made this calculator and other HP give up. I also know, of calculating the amounts Reimann with a spreadsheet, the convergence is slow. Is it really what the problem is here?

    I would recommend type 0. for your integration related. Who will throw directly into the approximate integration routines and not try to find a perfect, symbolic result for this type of problem that is not really possible without special constants.

  • Slow DAQmxWriteAnalogF64 in communication

    Hello

    I use a cDAQ-9174 chassis USB-9263 4xOutput module and the module 4xInput 9215. I want to set up a regulatory PID loop with entry and exit ao0 ai0. For this I need to know how fast he can talk to the computer to the output device a unique value, given that the computer needs to perform calculations based on input, he got and then decide on a release.

    To test the maximum rate of return, I created the loop next, based on the DAQmxWriteAnalogF64 function that I run inside a function on my program:

    errorChk (DAQmxCreateTask ("singleOutTask", & taskOut));
    errorChk(DAQmxCreateAOVoltageChan(taskOut,"cDAQ1Mod1/ao0","pidOutChannel",-10.0,10.0,DAQmx_Val_Volts,"")); "
    While (!) Stop) {/ / the loop runs until the stop = true.}
    outArray [0] = 0;
    errorChk (DAQmxWriteAnalogF64 (taskOut, 1, true, 10.0, DAQmx_Val_GroupByChannel, outArray, NULL, NULL));
    outArray [0] = 5;
    errorChk (DAQmxWriteAnalogF64 (taskOut, 1, true, 10.0, DAQmx_Val_GroupByChannel, outArray, NULL, NULL));
    }
    errorChk (DAQmxStopTask (taskOut));
    errorChk (DAQmxClearTask (taskOut));

    After you have created the task and the AOVoltageChannel program starts a loop where it will switch the power switch (0/5Vlts) output. Efectively, this creates a square wave on the output, I can assess his period with an oscilloscope and find the time to update output.
    With this code, I found that the output takes about 25ms to change, which implies a frequency of 20 Hz. It's too slow for my application.

    I got this code from the single output of NIDAQmx examples to create this loop, which, in many ways, is similar to what I should do to implement the PID controller.

    This communication seems very slow compared to the reading DAQmxReadAnalogF64 function that reads the values of a task of permanent entry, which means that the USB can communicate faster than that.

    Is there a way to output values faster? My computer can produce results of a calculation in any 1 (faster), so it would plant time to output values if the communication is fast.

    Thank you.

    If you need more information, please let me know.

    A. Vieira

    I found the answer.

    This is the example "Mult Volt updates-SW Timed.c" in examples of NOR-DAQmx. It uses the DAQmxWriteAnalogScalarF64 function to write values, instead of DAQmxWriteAnalogF64.

    With this feature my loop runs from a write at 1 kHz frequency 20 Hz.
    I had checked this example before and the reason why it was working not (apparently) so far, is that it uses DAQmxStartTask before entering the loop, even if autoStart is set to DAQmxWriteAnalogScalarF64. So if you start the task before you write values it works 50 x faster!

    Complete solution:

    float64 outValue;
    errorChk (DAQmxCreateTask ("pidOutTask", & taskOut));
    errorChk(DAQmxCreateAOVoltageChan(taskOut,"cDAQ1Mod1/ao0","pidOutChannel",-10.0,10.0,DAQmx_Val_Volts,"")); "
    errorChk (DAQmxStartTask (taskOut));
    While (!) Stop) {/ / the loop runs until the stop = true.}
    outValue = 0;
    errorChk (DAQmxWriteAnalogScalarF64(taskOut,1,10.0,outValue,)); With either autostart = 1 or 0 works perfectly
    outValue = 5;
    errorChk (DAQmxWriteAnalogScalarF64(taskOut,1,10.0,outValue,));
    }
    errorChk (DAQmxStopTask (taskOut));
    errorChk (DAQmxClearTask (taskOut));

    Maybe there are still some things we can do to improve it. I still believe that it woudn't be hard for bus connect even faster.
    I still dream with a way to make the device constantly write to a well-defined frequency (which can be very high) and the computer updates the memory buffer with the value next to write (or something similar). In this case, I just need to make sure that the computer writes the value into the buffer fast enough. So, it would be ideal! It would provide a frequency constant writing, with the example above does not.

    Thank you

  • How to multiply the channel by variable

    Hello

    I have a timestamp that is not real time, but the next number. I know that the interval (such as 1 or 10 seconds) of the measures. So I am this conversion to standard time. In this case, I need to multiply this channel by given interval. It's easy, because you can multiply the channel by a constant like below:

      Call ChnCalculate ("Ch(""[2]/Seconds1"") = Ch(""[1]/#"") * 1")
    Call ChnCalculate ("Ch(""[2]/Minutes1"") = Ch(""[2]/Seconds1"") / 60")
    Call ChnCalculate ("Ch(""[2]/Hours1"") = Ch(""[2]/Minutes1"") / 60")

    But how to do this using the variable? Let's say we have variable s_interval and we want to put this variable instead of multiplying it by constant.

    Ch(""[1]/#"") * 1 ")

    Do you know how to do this?

    Best regards

    Piotr

    Hi Piotr,

    You can set it like this:

    Dim dFactor
    Call ChnCalculate ("Ch(""[2]/Noise_1"") = Ch(""[2]/Noise_1"") /"& dFactor ")

    But I prefer a DIAdem function for this calculation, because it is faster using a well-defined function than the calculator.

    Dim dFactor, dOffset
    dFactor = 10
    dOffset = 0
    Call ChnLinScale ("[1] / Time", "[1] / Time", dFactor, dOffset)

    or if you use the channel object:

    Dim oChn, dFactor, dOffset
    Set oChn = Data.GetChannel("[1]/Time")
    dFactor = 10
    dOffset = 0
    Call ChnLinScale (oChn, oChn, dFactor, dOffset)

    Greetings

    Walter

  • How to recover formulas of the command stack?

    I'm making calculations across multiple data. I use the calculator to perform all the calculations. Stack command saves the last 20 transactions but I play more than 20 operations, and I would like to have access to see what I've done the calculations.

    There is no option file - save as the Analysis tab. How will I know what calculations I did on the channels, if I can't access the command stack formulas?

    Thank you

    Vandenplas has

    Hi Vandenplas,

    What version of DIAdem do you use?  If you are using version 11.1 or later, then I would recommend that you spend the channel for the calculation Manager calculator, which allows you to save and reload any number of calculations, as well as to bind the results of some on other entries.

    If you are using DIAdem 11.0 or earlier, then I recommend you to run the calculations of 20 + with a VBScript, using the ChnCalculate() command.  The interactive channel calculator was designed for fast interactive calculations, not tons of sequential calculations you want to use again and again.

    Brad Turpin

    Product development engineer of Suypport tiara

    National Instruments

  • The closest point of all in a table

    Hello

    I have two table 2D elements. Array1 and array2.

    I take a value from the array Array2 and calculate its distance from all elements of array Array1. I need to get the item that is the short of it. How is this posible?

    I did a VI. After that calculation of the distance how is it possible to check the short and how to keep that close to the value in a table?

    Please take a look

    Thank you

    Although I don't understand quite what kind of output you want, here's a possible solution that can probably point you in the right direction. Good luck!

    I assume that you want the value of the item to the nearest table and I guess by the distance you are talking about the 2D distance between two points in the complex plane. Other interpretations would be to get the closest value array indices, for example.

  • Simplify the VI that rate but currently uses too many shift registers

    I have a VI that was made by the Director of scary movie, so beware, this VI is a nightmare!... or at least for me, it is.

    Background:

    I have 20 pans and I have a water level sensor that generates a voltage of 0 to 5 Volts Output. By knowing the volume of the Pan, I calibrated the output to be in gallons. Real output I need is a volumetric flow, i.e. gallons per minute per square foot. We currently is key this by using a VI that a filed summer internship (see table). It works well, but it's so dirty and difficult to clean up and expand. The plan is to have 100 total pans and I don't want to copy paste this code 5 times more!

    Issues related to the:

    -How can I earn a rate differently? If you notice on the attachment Subvi calibration, the rate is calculated manually knowing how fast the loop going in the main VI. I don't know if this is the best way

    -Can I get rid of the shift registers some how?

    Is there a way for me to combine the subVIs in calibration so that I don't have a Subvi for each channel?

    Thanks in advance!


  • Increase the speed of this VI?

    It is a simple question - is anyway to increase the speed of the VI below?  Parallelize the outer loop, I'm given the sequential nature of the loop inside, I don't know if there is anything else I can do.  The problem is that I'm trying to eat a large amount of data - every second I'm producing about 1.25 MECH. / s and any attempt of this accumulate more than 10 s (Data In) to perform the calculations below on several periods of integration (iTime; currently 0.001 0.01, 0.1, 1 and 3 s) - and it is causing an overflow on some other loops.  Any help is appreciated.

    mtat76 wrote:

    Hmmm... isn't using table subset incur a calculation that does not remove the table?  I'll have at least one node of multiplication (I * chunk size) to add to the inner loop that was not there before to keep the appropriate place.  On the other hand, which gets rid of the shift register.  Is there a significant difference in performance between the subset of table and delete...?

    Looks like you're right about single-precision calculation - can be significantly faster.  I will consider this.

    Thanks, Darin.

    Matt

    You must test in LV12, in previous versions, remove that table is a dog, even when the end of the table is deleted.  I did a simple test, create a table of random numbers 50000 and take the average of the consecutive blocks of 400 items by using the two methods.  I even added a reverse table of subset test to match the behavior of deleting the table.

    Results:

    Delete: 2.7 msec

    Subset: usec 200

    your mileage may vary.

  • Help again...

    I never could get the cameras to work wireless, and I just now had time to run the cat5e cable in walls. I plugged the cameras directly to the router (wrt600n) and made sure the cameras worked. Everything is good - set a static ip address. Everything is good. When I plug it via my dlink gigabit switch 8 ports I can not get the light solid. Cut off each end and made sure they were wired right and that they were. I connected a laptop to the line, it connects through this switch. What Miss me? I plugged all other customers on that network; (2) Tivos Yamaha receiver, Wii, Ps3 and a printer. Nothing else has a problem with the switch. I do this thread as a crossover? I don't think, and I think that all new switches take care of that internally. Help!

    Dumpster says:
    I found that the connection is bad in the connector. With the help of cable Cat5E General and ideal ends. My (ideal) crimping tool is in good condition, no visible pin bent and saw occasional use only. I'm pulling my hair out, what little I have... I guess I'll buy some new connectors. Help if someone has suggestions. Thanks in advance, dm

    If you suspect your pliers to crimp or your technique is a failure, you must perform a few test stripping connections then the outer shell cable and pull each of the strands individually to see if they are properly fixed in the RJ-45. It is not uncommon that the outermost strands fail this test for one reason or another and it's good to know if you pay attention to this operation or maybe get a better tool. A lot of headaches to register here.

    I don't know if you installed a plug at the other end, but it's also a place where a connection problem, especially if you're a cheapskate like me and do not use the right tool (more often referred to as 'Krone-tool' where I live and standard equipment that we use).

    Good luck! But you should really start with checking with switch ports also of cables, IMHO, good known patch to address some points is not too rare failure.

    PS - some motherboards equipped with diagnosis of integrated wiring network interfaces. I have an ASUS card with a Marvell NIC do that, in the calculation of the distance to the hotbeds of tension in the cable. Maybe you have those advanced possibilities that are available to you without knowing... just saying '

  • Math.COS, Math.sin = Math.HELP

    Hi all

    I was hoping to create a JS script to move objects from the common center based on their current location. I thought to use an element of single selected path as the center based on its position x / y and width/height. Using this reference point that the script would then move away all other elements of the path of this central point based on a desired amount and with uniform increases, account required to their current location of this Center. I was thinking about cos and sin would be my friend in this case, but they seem to have become my enemy instead. ;-)

    Does this sound feasible? What Miss me, hurt, misinterpretation? Here's an attempt at non-working, I can't fix things, maybe I was close and missed or maybe I am so far and its complex more than I thought. However at this point I'm confused through my various attempts which is only one of them.

    Thanks in advance for any help and health mental someone can provide.

    // Example failed code, nonworking concept
    var docID = app.activeDocument;
    var s0 = docID.selection[0];
    pID = docID.pathItems;
    var xn, yn;
    var stepNum = 20;
    for (var i = 0; i < pID.length; i++) {
        var p = pID[i];
        var dx = ((s0.position[0] + s0.width) / 2 - (p.position[0] + p.width) / 2);
        var dy = ((s0.position[1] + s0.height) / 2 - (p.position[1] + p.height) / 2);
        xn = Math.cos(Number(dx) * Math.PI / 180)+stepNum;
        yn = Math.sin(Number(dy) * Math.PI / 180)+stepNum;
        var moveMatrix = app.getTranslationMatrix(xn, yn);
        p.transform(moveMatrix);
        stepNum+=stepNum;
    }
    

    Hi W_J_T, here's a way to do what I think you want to do, I put comment the increment so everything will "explode" the same distance, do not know if it is you need.

    first of all, I suggest the calculation of the center of the object selected out of the loop, you only need to do the math once.

    In addition, (s0.position[0] + s0.width) / 2 has a problem, it will not give you the Center, check below

    // calculate Selection center position
    var cx = s0.position[0] + s0.width/2;
    var cy = s0.position[1] + s0.height/2;
    

    then we're going to loop through all the elements and calculate their Center

            // calculate pathItem's center position
            var px = p.position[0] + p.width/2;
            var py = p.position[1] + p.height/2;
    

    We will pass the calculation of the distance from the center of the selection in the center of each item, we don't need this method, other methods may use this information.

    now, your real question on Sin / Cos

    xn = Math.cos(Number(dx) * Math.PI / 180)+stepNum;

    Sin (angle) and cos (angle) expect angles in Radians, you not provide any angle in the formula above. We need calculate the angle between the selection and each path Center

            // get the angle formed between selection's center and current path's center
            var angle = get2pointAngle ([cx,cy], [px,py]);
    

    as soon as we have the angle we can apply to our variable 'Explosion', I guess is stepNum and get its x and is distance he needs to walk away selection

            // the distance to move is "stepNum" in the same direction as the angle found previously, get x and y vectors
            var dx = stepNum*Math.cos(angle);// distance x
            var dy = stepNum*Math.sin(angle);// distance y
    

    everything remains to be done is to move the paths, here is the whole thing

    // Explosion, AKA move all items away from selection
    // carlos canto
    // http://forums.adobe.com/thread/1382853?tstart=0
    
    var docID = app.activeDocument;
    var s0 = docID.selection[0];
    pID = docID.pathItems;
    
    var stepNum = 20; // this is the distance to "explode"
    
    // calculate Selection center position
    var cx = s0.position[0] + s0.width/2;
    var cy = s0.position[1] + s0.height/2;
    
    for (var i = 0; i < pID.length; i++) {
        var p = pID[i];
    
        // skip selected item
        if (!p.selected) {
            // calculate pathItem's center position
            var px = p.position[0] + p.width/2;
            var py = p.position[1] + p.height/2;
    
            // get the angle formed between selection's center and current path's center
            var angle = get2pointAngle ([cx,cy], [px,py]);
    
            // the distance to move is "stepNum" in the same direction as the angle found previously, get x and y vectors
            var dx = stepNum*Math.cos(angle);// distance x
            var dy = stepNum*Math.sin(angle);// distance y
    
            var moveMatrix = app.getTranslationMatrix(dx, dy);
            p.transform(moveMatrix);
            //stepNum+=stepNum;
        }
    }
    
    // return the angle from p1 to p2 in Radians. p1 is the origin, p2 rotates around p1
    function get2pointAngle(p1, p2) {
        var angl = Math.atan2(p2[1] - p1[1], p2[0] - p1[0]);
        if (angl<0) {   // atan2 returns angles from 0 to Pi, if angle is negative it means is over 180 deg or over Pi, add 360 deg or 2Pi, to get the absolute Positive angle from 0-360 deg
            angl = angl + 2*Math.PI;
        }
      return angl;
    }
    
  • example of k-means algorithm

    can any give me an example to find the attribute class label using k-means algorithm, or please tell me where I can find it.

    by thanking everyone.

    You can use the k-means algorithm and change the calculation of the distance in mode (frequency). I found the code for average k in http://people.revoledu.com/kardi/tutorial/kMean/download.htm

Maybe you are looking for

  • buy for an aod257 of acer recovery media

    I see a lot of them listed online, but none of acer which is where I'd like to buy it if there is a link that someone could paste this would be wonderful Thank you

  • I forgot the password for Windows, need help

    I just restarted my computer and don't remember the password is there a way to make it work?

  • 3600n works not properly

    I have my 3600n hooked up to my network. When I try to print it does not find the printer. He does not see the levels of supply and when I ping the IP address, it returns the data. I'm on OS x Lion, and the correct 3600 driver is installed. Help, ple

  • I have a slow Internet connection under Windows 7.

    My son has a new computer and I bought a wireless adapter, but we have problems with the connection. My two sons have computers identical but different adapters. We're working correctly the other seems slower than dial-up! Original title: Internet co

  • Can't reinstall the drivers of the Photosmart C309 on OS 10.9.1

    Printer C309 printed after long periods of waiting and several times just a jiberish no pictures or pdf files. I removed the driver and tried to reinstall, but it says that Apple does not support the printer. HP driver support is no help as well. Any