1

I am new to bash scripting and have managed quite well until now without asking questions.

GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)

xubuntu 15.04

This has me stumped and I think the solution is simple and I am missing something fundamental, but I have been working on this for a week trying many permutations having read multiple threads with no change.

This snippet of code comes at the end of an image processing routine of any number of images separated into R G B channels and processed individually.

The files are prefixed in the order the channels were separated from the original images 0.tiff 1.tiff etc. Now I want to recombine them as follows;

renaming to r g b doesn't help because there can be a hundred or more r g b channels

       R G B
image1 0 1 2 ... and so on
image2 3 4 5 ...
image3 6 7 8 ... 

So, combine the first image channels 0 1 2, then increment the values of R G B by 3 to get the next image sequence 3 4 5 and so on.

3 grey channels are combining correctly evidence by correct alignment of the channels and production of a colour image.

The for loop combines 0 1 2 and fails on the rest. I think syntax is the problem in the for line - perhaps the enclosing of the variables R G B, though enclosing the variables does not seem to make a difference.

Otherwise, is it in the reassignment of R G B variables by the addition of 3?

I can usually work this sort of thing out but I have come to an end with it - hence the question...

 R=0
    G=1
    B=2

    echo "$R, $G, $B"

for i in {$R $G $B}; do convert $R.tiff $G.tiff $B.tiff -set colorspace sRGB -combine RGB_%d_$NAME.tiff

    let "R=$R+3"
    let "G=$G+3"
    let "B=$B+3"

    done

I did try naming a new variable such as ((newvalue=$R+3)) and assigining it to R R=$newvalue - same for G and B, but no change. Processes the first image only.

Thank you.

4
  • What is the highest value they are supposed to go up to ? Commented Jun 1, 2016 at 10:07
  • As many as required but a typical set 90 - 120 Commented Jun 1, 2016 at 10:19
  • How do you know how many are required i guess was my question. Do you have the amount in a variable, or do a count of something ? Commented Jun 1, 2016 at 10:20
  • The number of images is determined by exposure time and noise reduction when combining images and might run into hundreds. The script in development uses only 3 for testing with the separate RGB channels as global variables. Commented Jun 1, 2016 at 10:36

1 Answer 1

1

I don't fully understand the question as i don't know how convert works or if that is the problem but to increment all 3 variables by 3 each loop you can do a c style for loop.

for ((R=0,G=1,B=2;R<=100;R+=3,G+=3,B+=3));do

convert $R.tiff $G.tiff $B.tiff -set colorspace sRGB -combine "RGB_%d_$((x++)).tiff"

done

Assuming you have 33 values for the R<100

The problem with your script is that you only loop for each element in the expansion (so 3 times).

Sign up to request clarification or add additional context in comments.

5 Comments

various operators can be used with imagemagicks convert command - it's the main function - in this case setting the colorspace and -combine the images listed as input.
Can you combine the second 3 channels manually? i can't see any reason this loop would not work other than the convert command not working as you expect.
What's in $NAME? Are you overwriting the file every time?
$NAME contains the project name M8 in this case. Same behaviour with and without $NAME and or RGB. Perhaps the file name is not incrementing and overwriting?
All working! Excellent. Thank you. I now recall a similar problem with file names overwriting and worked around it - skipped my mind.

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.