Hi all,
Need to create a custom mask to an input tiff file, was wondering if anyone can start me off in the right direction on how to do so.
I have an 48RGB input tiff file (16 bits/channel), and need to mask out the lowest two bits, bits 0 and 1. (Basically am down-sampling to 14-bits/channel, but need to preserve in 16bits range). Is there an option already in ImageMagick to do this, or how can I create a custom mask that does this? The resolution of my input images can be variable
Thanks,
Srinath
Adding mask to input image
-
- Posts: 1
- Joined: 2015-08-31T12:34:52-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding mask to input image
2^14 - 1 = 16383
So this, I think, will work. It will scale all values from 2^16 - 1 (full 16-bit white) to 2^14 - 1 and the rest proportionally.
So this, I think, will work. It will scale all values from 2^16 - 1 (full 16-bit white) to 2^14 - 1 and the rest proportionally.
Code: Select all
convert image +level 0x16383 result
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Adding mask to input image
I don't think that's what the OP wants to do.
To zero the bottom two bits, you can "AND" with a number that is all binary one's but with zeros in the bottom two bits. In Q16, that number is 65535-3 = 65532.
An alternative is to shift bits:
To zero the bottom two bits, you can "AND" with a number that is all binary one's but with zeros in the bottom two bits. In Q16, that number is 65535-3 = 65532.
Code: Select all
convert in.png -evaluate And 65532 out.png
Code: Select all
convert in.png -evaluate RightShift 2 -evaluate LeftShift 2 out.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding mask to input image
Yes, I think you are right. I thought about the bit shift subsequently at lunch, but I did not know how to do that correctly.snibgo wrote:I don't think that's what the OP wants to do.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Adding mask to input image
Another way is to divide by 4 then multiply by 4. This won't work with HDRI.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding mask to input image
Could you not divide by 4, -clamp, then multiply by 4 in HDRI?snibgo wrote:Another way is to divide by 4 then multiply by 4. This won't work with HDRI.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Adding mask to input image
Clamp merely restricts the values to 0 to 100%, which they would be anyway. I don't think there is a simple supported way to "remove the fractional part" of HDRI values.
There is a way that works: OR with zero. It is a quirk so I wouldn't rely on this.
I suppose the bitwise operators AND, OR etc first convert values to integers.
There is a way that works: OR with zero. It is a quirk so I wouldn't rely on this.
Code: Select all
-evaluate divide 4 -evaluate Or 0 -evaluate Multiply 4
snibgo's IM pages: im.snibgo.com