Imagemagick แปลง tif เป็น rgba16 png

นี่คือภาพ tif ต้นฉบับของฉัน:

$ identify -verbose source.tif
Image: 
  Format: TIFF (Tagged Image File Format)
  Class: DirectClass
  Geometry: 512x512+0+0
  Resolution: 72x72
  Print size: 7.11111x7.11111
  Units: PixelsPerInch
  Type: Palette
  Base type: TrueColor
  Endianess: MSB
  Colorspace: RGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 1-bit

และฉันได้ลองแล้ว: แปลง source.tif output.png

และนี่คือผลลัพธ์:

$ identify -verbose output.png 
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 512x512+0+0
  Resolution: 28.34x28.34
  Print size: 18.0663x18.0663
  Units: PixelsPerCentimeter
  Type: Palette
  Endianess: Undefined
  Colorspace: RGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 1-bit

แต่ฉันไม่เห็นวิธีทำให้ PNG เป็น RGBA16 ซึ่งตามที่ฉันเข้าใจหมายความว่าต้องมีความลึก 16 บิตและช่องอัลฟ่า


person Greg    schedule 27.02.2015    source แหล่งที่มา
comment
นั่นคือบรรทัดคำสั่งทั้งหมดของคุณใช่ไหม ดูเหมือนจะไม่มีเหตุผลที่จะอัพเกรดช่องปลายทางเพราะแหล่งที่มานั้นเหมาะสมทุกประการ   -  person Jongware    schedule 27.02.2015
comment
ฉันไม่แน่ใจว่าฉันเข้าใจ   -  person Greg    schedule 27.02.2015
comment
รูปแบบอินพุตของคุณ 8-8-1 (ซึ่งเป็นเรื่องปกติ) ดูเหมือนว่าจะถูกแปลงเป็นรูปแบบเดียวกันทุกประการใน PNG คำสั่ง convert ทำตามที่คุณบอก ไม่มีอะไรเป็นมลทิน บางทีคุณอาจต้องบอกว่าคุณต้องการเอาต์พุต 16 บิต (ซึ่งถ้าฉันเข้าใจถูกต้อง จะต้อง ลดขนาดตัวอย่าง เป็น 4-4-4-4 แชนเนล)   -  person Jongware    schedule 27.02.2015


คำตอบ (1)


โดยทั่วไป ImageMagick จะใช้รูปแบบเอาต์พุต ประหยัดที่สุด ที่เข้ากันได้กับข้อกำหนดของคุณ ดังนั้น หากภาพที่ป้อนเข้าไม่มีช่องอัลฟ่า (เช่น ความโปร่งใส) ภาพที่ส่งออกก็จะไม่มีความโปร่งใส หากชุดสี 256 สีเพียงพอสำหรับสีในภาพของคุณ มันจะสร้างภาพที่ออกมาเป็นชุดสี หากความลึกของเอาต์พุต 8 บิตเพียงพอสำหรับรูปภาพของคุณ ก็จะไม่รบกวนการสร้างเอาต์พุต 16 บิต และอื่นๆ...

หากคุณต้องการ บังคับ ImageMagick ให้ทำสิ่งที่แตกต่างออกไป คุณมีตัวเลือกมากมาย

หากคุณต้องการ บังคับ สีจริง หรือไฟล์เอาต์พุตแบบพาเลท (จัดทำดัชนี) คุณสามารถทำได้ดังนี้:

convert input.png -type palette   output.png  # Force palettised (indexed) output
convert input.png -type truecolor output.png  # Force true colour output

หากคุณต้องการ บังคับ 8 บิตหรือ 16 บิต คุณสามารถทำได้:

convert input.png -depth 8   output.png  # Force 8-bit output
convert input.png -depth 16  output.png  # Force 16-bit (per channel) output  

หากคุณต้องการบังคับช่องอัลฟ่า/โปร่งใส คุณสามารถทำได้:

convert input.tif -type TrueColorAlpha output.png  # Force a true color output with transparency

และคุณสามารถรวมสิ่งเหล่านี้เข้าด้วยกัน หากคุณต้องการดูตัวเลือก type ให้ใช้คำสั่งนี้:

identify -list type

Bilevel
ColorSeparation
ColorSeparationAlpha
ColorSeparationMatte
Grayscale
GrayscaleAlpha
GrayscaleMatte
Optimize
Palette
PaletteBilevelAlpha
PaletteBilevelMatte
PaletteAlpha
PaletteMatte
TrueColorAlpha
TrueColorMatte
TrueColor

นอกจากนี้ โดยเฉพาะในกรณีของไฟล์ PNG คุณยังสามารถ บังคับ เอาต์พุตได้โดยการระบุประเภท PNG เป็นตัวพิมพ์ใหญ่ ตามด้วยเครื่องหมายทวิภาคหน้าชื่อไฟล์เอาต์พุต ดังนี้:

convert input.tif PNG64:output.png     # Force 64-bit RGBA (3 channels @ 16-bits each, plus alpha)
convert input.tif PNG32:output.png     # Force 32-bit RGBA (3 channels @ 8-bits each, plus alpha)
convert input.tif PNG48:output.png     # Force 48-bit output (3 channels @ 16-bits each, no alpha)
convert input.tif PNG24:output.png     # Force 24-bit output (3 channels @ 8-bits each, no alpha)

ดังนั้นคำตอบสั้นๆ ก็คือ

convert input.tif PNG64:output.png

or

convert input.tif -depth 16 -type TrueColorAlpha output.png

ระวังให้ดี ImageMagick จะแทนที่เวอร์ชันที่สองหากไม่มีช่องอัลฟาในภาพอินพุตของคุณ ในขณะที่มันจะไม่ทำเช่นนั้นหากคุณใช้ PNG64:

person Mark Setchell    schedule 28.02.2015
comment
ขอบคุณสำหรับคำอธิบาย! แล้วทำไมถึงเป็น PNG64 ถ้าฉันต้องการ rgba16? - person Greg; 02.03.2015
comment
เพราะ 4 ช่อง @ช่องละ 16 บิต = 64 - person Mark Setchell; 02.03.2015
comment
ด้วยเหตุผลบางอย่าง ฉันได้รับข้อผิดพลาดนี้ด้วยคำสั่ง: แปลง: ไม่สามารถเปิดรูปภาพ `PNG64:output.png': @ error/blob.c/OpenBlob/2517 - person Greg; 04.03.2015
comment
จะเกิดอะไรขึ้นถ้าคุณเรียกใช้ convert -size 100x100 xc:black a.png - person Mark Setchell; 04.03.2015
comment
ดูเหมือนว่าฉันจะขาด TrueColorAlpha ไปด้วยเมื่อฉันเรียกใช้ ident -list type - person Greg; 04.03.2015
comment
ตกลง ลอง convert -size 100x100 xc:black PNG64:a.png - person Mark Setchell; 04.03.2015
comment
ฉันคิดว่าคุณมีเวอร์ชันเก่าแล้ว ลอง identify -version - person Mark Setchell; 04.03.2015
comment
ในคำสั่งก่อนหน้าของคุณฉันได้รับ: Convert: no encode delegate for this image format `PNG64:~/a.png' @ error/constitute.c/WriteImage/1189 - person Greg; 04.03.2015
comment
สำหรับเวอร์ชันที่ฉันได้รับเวอร์ชัน: ImageMagick 6.6.4-1 2010-12-17 - person Greg; 04.03.2015
comment
มันเก่ามาก :-( คุณจะต้องอัปเดตอย่างแน่นอน - person Mark Setchell; 04.03.2015