Resize without altering the palette (solved)

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?".
Post Reply
etpicb

Resize without altering the palette (solved)

Post by etpicb »

I am converting a movie from ntsc to pal, the subtitles (as the movie) need to be converted from the resolution of 720x480 to 720x576.

The subtitles are 8bits png files with at most 4 colours (one being the transparency), to convert all the files I used:

Code: Select all

for d in *.png ;do
convert "$d" -resize '720x576!' -colors 4 tmp.png || break
mv tmp.png "$d"
done
Unfortunately every subtitle file must use the _same_ four colours.
Using convert this way the four colours in each file can be (and are) different.

How can I force convert to maintain the original colours or how can I set the palette?

Thanks.
Last edited by etpicb on 2009-07-01T06:27:59-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize without altering the palette

Post by fmw42 »

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Resize without altering the palette

Post by anthony »

If you resize using -sample only the original colors will be used. But at a loss of quality!

The other method as pointed out by fred, is to re-map the image to just the four colors desired. You may or may not want the dither for this (turn of dither with +dither)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
etpicb

Re: Resize without altering the palette

Post by etpicb »

To anyone interested:

You can convert your DVD subtitles from one resolution to an other extracting them with

Code: Select all

tccat -i /dev/sr2 -T 8,-1 | tcextract -x ps1 -t vob -a 0x20 > subsen
mkdir subtitles
cd subtitles
subtitle2pgm -i ../subsen -c 224,224,32,0 -g 4 -t 1 # <-- verify the vaules of -c they depends on the movie(1)
convert all the png files with

Code: Select all

for d in *.png ;do
  convert "$d" -resize '720x575!' +dither -map "$d" tmp.png || break
  mv tmp.png "$d"
  echo "$d"
done
mixing them in the mpg file with the movie with

Code: Select all

spumux -s0 movie_subtitle.dvdxml <../movie.mpg >../movie_wsubs.mpg #<-- increase the -s value if it is not the first subtitle
and finally you can author your dvd with the mpg file.

About (1)
I usually use `-c 0,85,170,255' to see how is the palette and assign black to the background, white inside the letters and dark gray around.

Thanks everyone.
Post Reply