-2

I am trying to take two .nii images and pull random voxel coordinates with non-zero intensity from the first image and then compare that intensity value with the same voxel in a different image. These images should be the same and thus nothing will happen if the values match up. I am struggling on how to find the intensity of a specific voxel in an image with specified coordinates.

max_vox_coord_ref=$(fslstats $image_file1 -x)
max_vox_coord_arr=($max_vox_coord)
max_vox_inten_ref=$(fslstats $image_file1 -R) #### this isn't saving as an array

declare -i dimx dimy dimz
dimx=${max_vox_coord_arr[0]}
dimy=${max_vox_coord_arr[1]}
dimz=${max_vox_coord_arr[2]}
#dimy=${max_vox_coord_arr[1]}
#dimz=${max_vox_coord_arr[2]}


image1_int=$(fslmeants -i "$image_file1" -c $dimx $dimy $dimz)
image2_int=$(fslmeants -i "$image_file2" -c $dimx $dimy $dimz)

if [ $image1_int -ne $image2_int ]; then
    echo "VIBES AINT THERE"
    fslview $image_file3 $image_file3 $image_file1 -l Red -t 0.7
else
    echo "They equal"
    fslview $image_file3 $image_file1 -l Red -t 0.7
fi

I then try calling on the second value from this answer to get the max intensity to match up with the max intensity voxel. I fail from here in finding a way to use the found voxel from image1 and get the intensity from the same coordinates in image2.

  • Please take a look at [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting). – Cyrus Aug 09 '23 at 22:40
  • You'll also need to include a small set of sample data, the required output from that data, your code, current output and err Msgs. We're here to help you fix your code, not to do it for you. Generally `awk` can easily handle manipulation of text and data (numbers) with a minimum of hassle. Maybe you need [Awk Tutorial](https://grymoire.com/Unix/Awk.html). Good luck! – shellter Aug 09 '23 at 23:11
  • I added more context to my code, hope this helps people understand and help! – braincodelearner Aug 10 '23 at 15:03
  • Indeed, `string=$(output)` assigns a string, not an array. Nothing in its documentation claims it creates an array. To know how to modify it to generate an array, we'd need to know more about the format of the output of `fslstats`; sometimes you want `read -a`, sometimes you want `readarray` or `mapfile`; sometimes you want a hand-built loop. – Charles Duffy Aug 10 '23 at 15:05
  • It would probably do a lot of good here if you could structure the question so people who just know bash -- and don't know fslab -- can usefully answer it. Can you build a [mre] where instead of calling fslab programs you call contrieved programs whose output can be handled -- or mishandled -- in the same way? Easy to build a one- or two-line function that writes exactly the output you want to showcase handling for, after all. – Charles Duffy Aug 10 '23 at 15:06
  • BTW, there are a bunch of quoting bugs in this code that https://shellcheck.net/ will identify. The difference between `$foo` and `"$foo"` is real and substantive. – Charles Duffy Aug 10 '23 at 15:07
  • @CharlesDuffy truthfully, I am only looking for a way to pull the intensity value of a specified voxel out of an image. The comparison between the two images is easy enough. Currently my knowledge of packages only extends to extracting the maximal value intensity voxel and not a specified voxel. – braincodelearner Aug 10 '23 at 17:30
  • Again, _my expertise is only in bash but not in fslab_. Consequently, I don't know what format fslab tools emit the data you need in, so describing which data you need doesn't give me enough information to script extraction of that content. If you included that information in the question rather than requiring someone to know it to answer, I could probably help. – Charles Duffy Aug 10 '23 at 20:14
  • @CharlesDuffy Do you have a BASH script that can extract the intensity of a specific voxel of an image? It doesn't need to use any FSL tools. Thank you for all your advice. – braincodelearner Aug 10 '23 at 20:55

0 Answers0