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

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

Post by gaylorr »

I have a unique case where I have values in a texture for a 3D model that all represent the "angles" of the orientation of the polygons of said 3D model.

Basically:
I want to choose from an image the single value for vertical faces...which is represented by R: 132...and all of the values (0-255) for B and G and have that selection set be dumped into a new image with no other background pixels (not alpha, just no other colors and not black or white.)

I have tried searching the forum and understanding the command possibilities, but can not figure this out.

Is this possible?

ps I will be doing all of this in windows batch, not perl, etc.

Thanks in advance!
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 »

BTW, I would prefer the new image was simply image with all of the values in the requested selection set being filled to "white" with no other background

Thanks!
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 »

I don't understand what you want.
gaylorr wrote:... be dumped into a new image with no other background pixels (not alpha, just no other colors and not black or white.)
"no other background pixels"? An image has pixels. Pixels have colours. They may be opaque, or have an alpha value.
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 »

When I open a PNG or PSD in photoshop, it "can" have no alpha, but still have not every pixel in the image have a color value...interlaced...that is what I would prefer the final image be, because I will be running other processes on the resultant image. So I guess I should have just said the result will end up an interlaced .png for further processing...sorry.
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 »

Sorry, I've never heard of interlaced .png, and don't know how to make one.
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 »

just as an FYI...so it gets explained better than I can:

https://en.wikipedia.org/wiki/Portable_Network_Graphics
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 »

see http://www.imagemagick.org/script/comma ... #interlace. Though I do not understand how this makes any difference to other processing. It just stores the pixel data in an r,g,b per row format rather than r,g,b per pixel format or r,g,b per channel format. It does not skip any pixel values. They are all there in any of these formats.

Perhaps you really mean -type pseudocoloralpha i.e. PNG8 with an alpha color rather than -type truecoloralpha i.e. PNG32 with an alpha channel. If that is the case, then write your image with PNG8: or PNG32: prefix.

convert image PNG8:resultimage
convert image PNG32:resultimage

See http://www.imagemagick.org/Usage/formats/#png

I am not sure what this has to do with the original question, though.
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 »

that could be very true...the resultant output really isn't my issue...but rather how to select exactly what I want from the image. I figured out how to choose a single RGB value, but what I want is a single R value, and ALL of the G and B values and generate some new image from that, filling those result values to white...that's all...

I am sorry if I am over complicating this request, I really am...just a newb to ImageMagick, although I can't figure this out in Photoshop either oddly enough.
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 »

I want to choose from an image the single value for vertical faces...which is represented by R: 132...and all of the values (0-255) for B and G and have that selection set be dumped into a new image with no other background pixels (not alpha, just no other colors and not black or white.)
There is no image format that has only these values and nothing else, unless you write only these pixels to a single row or column of data. But then you lose the context of where each original pixel comes from.

You could write it out to a text file, however, with something like the following in unix.

Code: Select all

convert image txt:- | grep "rgb(132" > data.txt
see http://www.imagemagick.org/Usage/files/#txt

IM can then read that back into image format, but you will need to tell it what background color you want for all the other pixels, typically transparent.

If you want to do that in one command, then

Code: Select all

convert image txt:- | grep "rgb(132" | convert - -background none newimage
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 request I made has gotten skewed by the format hangup...I just want to select a range of colors (R=132, G=0-255, and B=0-255) and create an image of white from those values...if the resulting image has alpha or even some other background color (non-white) isn't the part I can't figure out...it's the selection of the above range.

Am I making sense? ;-)
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 »

perhaps if I reduce all of the R values that are not 132 to black, the R=132 to white, and all other non-0 pixel values in the G and B channels to white ?
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 »

One way is (unix syntax)

Code: Select all

convert image txt:- | grep "rgb(132" | convert - -background none -channel rgba -fill white +opaque none newimage
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:One way is:

Code: Select all

convert image txt:- | grep "rgb(132" | convert - -background none -channel rgba -fill white +opaque none newimage
I tried this at a windows command prompt and it complained about grep?
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 »

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
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 »

LOL...oh...damn...sorry.
Post Reply