Picking a single RED value, and all the G and B (0-255)

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?".
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

fmw42 wrote:As I said that was a unix command. It does not work on windows.


try

Code: Select all

convert image -channel r -separate +channel -fill black +opaque "gray(132)" -fill white -opaque "gray(132)" result
I think that worked!!! (it's a hell of a lot closer than I got anyway ;-) )

Thank you!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Picking a single RED value, and all the G and B (0-255)

Post by snibgo »

Do you want an image as the output, or text? If an image:

Should it be the same size as the input image?

Some of the input pixels have red equal to 132 (out of 255). What do you want in the corresponding output pixels?

For the inputs that don't have red=132, what do you want in the corresponding output pixels?

EDIT: Never mind, Fred seems to have understood what you want.
snibgo's IM pages: im.snibgo.com
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

thank you tho also for helping me clarify what I needed Snibgo...I appreciate the help always...

In the above provided solution by Fmw42, if I wanted to have it choose red values that were say between 125 and 145 (thus capturing the range of R) could this command line script be modified to do that as well? (versus only capturing "132")
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Picking a single RED value, and all the G and B (0-255)

Post by snibgo »

"-fuzz 7" may do what you want.
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: Picking a single RED value, and all the G and B (0-255)

Post by fmw42 »

snibgo wrote:"-fuzz 7" may do what you want.
Only on Q8 systems. On Q16 that would be 7 out of 65535. So better to use percent such as 7/255 => 2.7451%
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Picking a single RED value, and all the G and B (0-255)

Post by snibgo »

Ah, yes, true.
snibgo's IM pages: im.snibgo.com
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

snibgo wrote:"-fuzz 7" may do what you want.
I did try to understand the "fuzz" factor, but it seemed a bit not really controllable accurately...
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

fmw42 wrote:
snibgo wrote:"-fuzz 7" may do what you want.
Only on Q8 systems. On Q16 that would be 7 out of 65535. So better to use percent such as 7/255 => 2.7451%
Ahhhh....now I see how to lock that down...thanks!
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

Where could I put the -fuzz in this line:

convert filename.dds -channel r -separate +channel -fill black +opaque "gray(132)" -fill white -opaque "gray(132)" filename.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Picking a single RED value, and all the G and B (0-255)

Post by snibgo »

Anywhere before "+opaque".
snibgo's IM pages: im.snibgo.com
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

snibgo wrote:Anywhere before "+opaque".
Thank you Snibgo...and for all the replies and patience to my Noobism ;-)

I really really love what I have found out that ImageMagick can do...just going thru and trying to read every page of options, tools, example...I mean...this opens up so much more for me than photoshop (not that it isn't amazing in how far it has come over the years too) but I work in the visual simulation world, and once I know this tool much better, I plan on never having to use Pshop Actions ever again! I can't batch using IM so much more efficiently and repeatably once I understand more.

Anyway...thank you again for helping me get started.

Rick
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

I think the command line argument / script is giving me colors I do not want...

convert file-in.dds -channel r -separate +channel -fill black -fuzz 5% +opaque "gray(132)" -fill white -opaque "gray(132)" file-out.png

the RED color channel is the only color that the range can be selected from based on the formula:
color r = face->normal().z * 127.0 + 127.5;
color g = face->normal().y * 127.0 + 127.5;
color b = face->normal().x * 127.0 + 127.5;

I am trying to select all vertical faces (within a 5º margin of error) in my model's texture.
the gray(132) as I read it, means:
gray = rgb(126, 126, 126)...

what I want is:
rgb(132, *, *)
OR an exact colors: (as an example)
R=127-224
G=*
B=*

Is this possible?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Picking a single RED value, and all the G and B (0-255)

Post by fmw42 »

It is giving you 5% on each side of 132. In this context it is only 5% on each side of red=132 due to the use of -channel r -separate. You must compute the range of values on each side of the center of the range and use the center of the range as the gray value.

For example 105% of 132 = 139 and 95% of 132 = 125 (rounded to the nearest integer). So you will get red in the range of 125 to 139 and all values of green and blue for those red values.
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Picking a single RED value, and all the G and B (0-255)

Post by gaylorr »

fmw42 wrote:It is giving you 5% on each side of 132. In this context it is only 5% on each side of red=132 due to the use of -channel r -separate. You must compute the range of values on each side of the center of the range and use the center of the range as the gray value.

For example 105% of 132 = 139 and 95% of 132 = 125 (rounded to the nearest integer). So you will get red in the range of 125 to 139 and all values of green and blue for those red values.
Ok thank you...

Perhaps in a later release there could be a -range(125-132) ?

;-)

Rick
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Picking a single RED value, and all the G and B (0-255)

Post by snibgo »

fmw42 wrote:For example 105% of 132 = 139 and 95% of 132 = 125 (rounded to the nearest integer).
?????

"-fuzz 5%" means 5% of quantum. If quantum is 255, then 5% of this is plus or minus 13. If the central value is 132, we will get values of 119 to 145.

If the desired range is 125 to 132, then the central value is 128.5, and the percentage fuzz should be 100*3.5/255 = 1.3725%
snibgo's IM pages: im.snibgo.com
Post Reply