mergeing stips with offset

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

mergeing stips with offset

Post by imaggie »

Hi,

I have an image which is a lot of stips one under the other. So far I have split them into separate images.

Code: Select all

convert  input.jpg  -crop 1648x128 +repage  out_%03d.png
next I recompose them using every third strip: ( it's actually the 3 RGB layers interleaved )

Code: Select all

convert out_234.png out_237.png out_240.png out_243.png -append out-collate.png
So firstly with that many images I want to do that automatically. Is that possible with IM6 or do I need to do that in a loop script calling convert.

Secondly the images have a few pixels of duplication, so I want to supply an y offset of fixed magnitude each time I collate a strip.

Now I know IM6 is amazingly powerful but parsing all the doc to find out how to do this is getting to look like a three year degree course.

Can someone shorten my pain by pointing me in the right direction, please?

Many thanks.

[EDIT] As requested: using ImageMagick 6.9.2-7 Q16 x86_64 Linux
Last edited by imaggie on 2016-09-02T00:20:13-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mergeing stips with offset

Post by fmw42 »

Please always provide your IM version and platfom. In stead of using +append, you can use montage with -geometry -X+0 to get some overlap. See http://www.imagemagick.org/Usage/montage/#overlap. If that does not help, then please post a few of your images that you want to append to some free hosting service such as dropbox.com (public directory) and put the URLs here.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: mergeing stips with offset

Post by snibgo »

To handle the "every third strip", you probably need a script. How many strips per source image?

For speed, you can do things like this (in Windows BAT):

Code: Select all

convert input.jpg -crop 1648x128 +repage -delete %DEL_LIST% -append out-collate.png
For bash, you would have %(DEL_LIST).

Before do the convert, the script would set DEL_LIST to be 0,1,3,4,6,7,9,10 and so on.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mergeing stips with offset

Post by fmw42 »

I believe on bash it would be

del_list="0,1,3,4,6,7,9,10"

then to use it,

-delete $del_list

or perhaps

-delete "$del_list"

Not sure it should matter
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: mergeing stips with offset

Post by snibgo »

Thanks, Fred. I'm hopeless at bash.

The job sounds quite simple. But, rather than creating all the slices, saving them as files, then reading every third one, it may be easier and quicker to do all the processing in a single convert.

If the OP puts up a source image, we may be able to advise better.
snibgo's IM pages: im.snibgo.com
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

Thanks, I can create the list of numbers in bash and use a shell variable as suggested.

Code: Select all

list=`seq -s , 1 3 10`
echo $list
1,4,7,10

I was wondering whether fx can do that sort of thing.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

Hmm, having trouble getting the list arg to work:

Code: Select all

convert  input.png  -crop 1648x128  +repage  -delete "$list"  -append  out_%03d.png

convert: geometry does not contain image `input.png' @ warning/transform.c/CropImage/716.
Last edited by imaggie on 2016-08-31T16:14:12-07:00, edited 1 time in total.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

snibgo wrote:Thanks, Fred. I'm hopeless at bash.

The job sounds quite simple. But, rather than creating all the slices, saving them as files, then reading every third one, it may be easier and quicker to do all the processing in a single convert.

If the OP puts up a source image, we may be able to advise better.

I agree it's probably best done in one hit. But IM is as cryptic as hell so I like to do things in little bits, then get clever once it seems to work ;)

It's the Juno Earth fly-by efb12 I'm playing with. They're rather large but if you'd rather have the image ::
http://www.msss.com/junocam_efb/efbimg.html

I expect the whole exercise will a single IM command at the end of it.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

Code: Select all

convert  junocam_efb12.jpg -roll +0+3328  -crop 1648x9856 -delete "1,2,3"   junocam_efb12_roll.png
OK, the geometry thing is something else. I had rolled and cropped to get rid of all the dead wood and get a more managable file size. It looks OK in display or GIMP and file reports sensible dimensions etc but convert does not seem to want to work with it again afterwards :?

I've had this kind of thing with IM in the past, I think, can someone remind me what extra tweak it needs ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mergeing stips with offset

Post by fmw42 »

try

-delete 1,2,3

no quotes

Note image indices start with 0, not 1

You may also want to add +repage after the crop to remove the virtual canvas.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

yes thanks, I've found the missing +repage.

This is behaving sensibly now. I need three lists made by seq to skim out each colour plane,

Code: Select all

 list1=`seq -s , 1 3 76`
 list2=`seq -s , 2 3 76`
 list3=`seq -s , 0 3 76`

it works OK like this:

Code: Select all

 convert  junocam_efb12_roll.png  -crop 1648x128  +repage -delete "$list1,$list2"  -append efb12_collate.png
Now I need to lose the last 13 rows of each strip which are duped.but adding in another crop does not seem to make any difference :?

Code: Select all

convert  junocam_efb12_roll.png  -crop 1648x128  +repage -delete "$list,$list2" -crop 1648x115  +repage  -append efb12_collate.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mergeing stips with offset

Post by fmw42 »

Perhaps I misunderstand what you are doing.

You should be able to delete the last 13 rows by:

Code: Select all

convert  junocam_efb12_roll.png  -crop 1648x128  +repage -delete "$list,$list2" -delete -1--13 -append efb12_collate.png
See http://www.imagemagick.org/Usage/basics/#list_ops

EDITED: Removed first crop concept, since I do not know how many good rows you have.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

Thanks but it's not the strips I want to remove here, it's the lower 13 pixel rows of ALL the strips which remain after

Code: Select all

-delete "$list,$list2"
just before the final append.

OK this seems to do it. I could not work out why -crop didn't do it, but I was not providing the offsets.

Code: Select all

 convert  junocam_efb12_roll.png  -crop 1648x128  +repage -delete "$list,$list2" -crop 1648x115+0+13  +repage  -append efb12_collate.png
I actually need to do the roll and crop after the splicing , it was good enough to speed up processing while I debugged it though.

Now I just need to do the aoove three times with the different $list arguement and collate the the three 8 bit grayscales into a 24bit RGB.

Thanks for the help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mergeing stips with offset

Post by fmw42 »

If your problem is getting crops that are not full size regions, seems to me that it would be better to initially crop your input image to a multiple of your crop sizes rather than trying to remove them at the end.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: mergeing stips with offset

Post by imaggie »

fmw42 wrote:If your problem is getting crops that are not full size regions, seems to me that it would be better to initially crop your input image to a multiple of your crop sizes rather than trying to remove them at the end.
No, it's in the other direction. I have wide, short ( y ) strips which have some ( 13ox ) duplication in y. So it makes sense to cut into strips and then remove a bit across the bottom of each strip. The line above seems to do the job.


My problem now is that there is an x shift from one strip to the next. This means that I need to compose the crop arguments using -fx and the image count n but it does not want to play. What is the correct way to go about this?

Code: Select all

 -crop 1648x115+'%[fx:n*5]'+13  
convert: invalid argument for option `-crop': 1648x115+%[fx:n*5]+13 @ error/convert.c/ConvertImageCommand/1176.

thx.
Post Reply