1

I have an image of atomic columns and I want to store the X- and Y-coordinates of maximum value of each atomic column but I don't know how to write the script to store bunch of data as an array. Please help me.

3
  • This question is not very clear. Do you mean you need help with storing multiple XY values (in an array), or with finding these values from the image? Commented May 27, 2017 at 20:51
  • @BmyGuest sorry if my question is not clear. Yes, I do mean by storing multiple XY values in an array. Commented May 29, 2017 at 2:51
  • @BmyGuest Thank you for suggesting a clearer question title! :D Commented May 29, 2017 at 12:58

1 Answer 1

0

I am not sure I unstand the question, but if you are just looking to store multiple values in an "array" then you just need to recognize that any 2D image already is an array. If you want to store n XY-pair values, then you can simple create a [n x 2] image and store the values there. Some example:

number n = 30       // number of pairs
image data := Realimage( "Data Array", 4, 2 , n )

for( number i = 0 ; i < n ; i++ )
{
    number xValue = i * 10                              // just something
    number yValue = xValue * sin( xValue / 100 * PI() )     // just something
    data.SetPixel(0, i, xValue )                // Set X at position i (first column)
    data.SetPixel(1, i, YValue )                // Set Y at position i (second column)
}

data.ShowImage()

// You may want to display the image as "Spreadsheet". (Type 7)
data.ImageGetImageDisplay(0).ImageDisplayChangeDisplayType(7)

// And you may want to label the columns
data.ImageGetImageDisplay(0).SpreadSheetImageDisplaySetColumnLabel( 0, "X values" )
data.ImageGetImageDisplay(0).SpreadSheetImageDisplaySetColumnLabel( 1, "Y values" )

Image displayed as spread-sheet

You don't have to use SetPixel(). You can also set pixel values by indexing the position.

 data[0, i] = xValue // Same as: data.SetPixel( 0, i, xValue )
Sign up to request clarification or add additional context in comments.

5 Comments

@Aning: Great. I just want to add to this, that depending on your further aims with that list, another option would be to store the data in TagGroups or TagLists. There are some advantages (like easier "sorting" and ammending new - non scalar value - data) but also disadvantages (images can be used in image-expression calculations which are way faster than relying to single-value extraction).
Thanks for the suggestions! Actually, later (in a separate script) I need to refer back and use the XY values that are stored in the array. Is it possible to do that? (I am sorry if, again, my question is not clear as I am not good in English. sorry)
Yes, you simply use "GetPixel" instead of "SetPixel". But depending on how you need these numbers - just one of them, or all one-by-one - there might be more efficient ways to use image expressions instead.
I would like to ask.. Is it possible to call arrays in a separate script with the one that was used to create arrays? (Sorry for my messy English. I mean, say, arrays are created in script A. I want to call these arrays in script B) Is it possible?
@Aning Maybe you should ask differnt things in separate questions so that they can be searched for by others more easily. But as a quick answer: If you display an image, it stays open and in memory when the script finishes, so another script can start with that image. Alternativly, you can store an image (or info) in the Global tags (or on disk). Finally, you can write one single script with multiple functions and then have this single script do all of it. The best solution very much depends on what you want to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.