Image processing in Snap!

Yes thank you, I believe this will work. However, do you know if there is a function similar to a java function like arr[i][j] to access a certain indeci in the array, I tried looking for that but I couldn't find it.

something to replicate a nested for loop

for( int i =0; i<arr.length; i++){
for( int j =0; i<arr[0].length; i++){
System.out.println(arr[i][j]);
}
}

getting this error now

You need to drag the i and j variables into your item of - just typing in i or j isn't the same thing

And I think you need to change your reshape to be like the one in this post

what does this reshape do

Each pixel is represented by 4 values red, green, blue and alpha (RGBA)

So the reshape arranges the pixels into the a 2D matrix with each point containing the RGBA value of a pixel

do you know where I can access this pixel library? I cant find it.

Menu :file_icon: > Libraries... > Pixels


doing this results in each indices of the 2d array having a array of its own, how would I then convert this back into a normal 2d matrix with grey scale values. Is there a snap method which automatically converts a rgb image to a grey scale?

You could do this: ( sum ( item ( numbers from ( 1 ) to ( 3 ) ) of ( list [110][110][110][255]@delInput@addInput ) ) ) / ( 3 ) That will get the average pixel color in the quickest way.

It's also good to round it.

We don't really have multi-dimensional lists; instead we have lists of lists. That's why everyone is telling you to use nested ITEM blocks. But in fact we do have a sort of shortcut for that: you can call ITEM with a list of lists as the first input:
Untitled script pic (11)
The reason it has to be a list of lists, not just Untitled script pic (12), is that you can put more than one number in each sublist to select a subarray, e.g.,
Untitled script pic (13)
will select items [1][6], [1][8], [1][9], [3][6], [3][8], and [3][9] as a submatrix.

Untitled script pic (12) would select rows I and J of the array.

About the RESHAPE block, bear in mind that a picture is actually a 3D array, not a 2D array, because each pixel is itself a list. So
Untitled script pic (14)
will select the Green value of the third pixel in the fourth row.

You should read the Hyperblocks section, pages 55ff of the Reference Manual, for all the gory details.

untitled script pic - 2024-10-24T230523.453

@ Pixels library


untitled script pic - 2024-10-24T230429.812
untitled script pic - 2024-10-24T230434.599


Everything is working so far, all I need is to fill "grad" an empty matrix with the gradMag, an integer, at each point. Any ideas on how to do this?

untitled script pic (7)

untitled script pic (6)


this is working, but the for loop takes forever. Do you guys have any recommendations to speed up the code?

try putting it in a warp{ } block.

this does help a little, but it still takes very long through iterate through. The array is about 360x360.

Nvm, this helped. Thank you.

I think that sum of convolution results is equal to convolution with the sum of the kernels.
untitled script pic - 2024-10-25T215413.961 == untitled script pic - 2024-10-25T215418.357

To see the effect of the transformation you may create the "grayscale" costume
filter script pic (2)

To test the convolution kernels you may directly convolve the costume data with
filter script pic (3)
The resulting image of Sobel(X)+Sobel(Y)

I'm not sure what your goal is, but there is filter script pic (4)