How to replace all pixels of some color in a bitmap in Rebol? - rebol

Let's say I have a picture, I want to create some variations by changing a color. How to do this ?
I don't want to apply color filter to a picture, I want to change pixels color pixel by pixel by testing a color pixel if it is let's say red, i want to turn it to blue.

In Rebol images are also series, so you can use most of the series functions to change/find rgb colors etc.
i: load %test.png
type? i
image!
first i
255.255.255.0 (the last value is alpha)
change i 255.0.0.0 ;change the first rgba value to red
view layout [image i] ;you can see the upper-left pixel is now red
you can dump all rgba values in an image:
forall i [print first i]
you can also change a continues part:
change/dup head i blue 100 ;change first 100 pixels to blue
you can also work on i/rgb and i/alpha, these are binary values (bytes)
and you can use copy to get a part of an image:
j: copy/part at i 100x100 50x50 ;copy from 100x100 to 150x150 to a new image.

Use some of the image processing capabilities as documented here:
http://www.rebol.com/docs/view-guide.html
Demo program showing some of them in action here:
http://www.rebol.com/view/demos/gel.r

Related

How do I see the actual color of a single RGB value in Google Colab?

Very basic question. I have a single vector (e.g., [53, 21, 110]) and I want to print the RGB color it represents in a colab notebook. Like a color swatch. What's the simplest way to do this?
The simplest way would be using the Image module from PIL. According to the documentation, you can construct an image with:
PIL.Image.new(mode, size, color=0)
mode [required]: determines the mode used for the image, it can be RGB, RGBA, HSV, etc. You can find more modes in the docs
size [required]: this is a tuple (weight, height) that represents the dimensions of your image in pixels.
color [optional]: this is the color of the image, it can receive a tuple to represent the RGB color in your case. The default color is black.
Then, to show the image within colab, you would use
display(img)
Given your question, the mode would need to be 'RGB' and if your vector is a list, you need to convert into a tuple to use it.
To show an 300px by 300px image, the code would look like.
from PIL import Image
img = Image.new('RGB', (300,300), color = (53, 21, 110))
display(img)

How can I find the amount of pixels in part of an image?

I have an image and I want to see how many pixels are in different parts of the image. Is there a software I can use to do this?
In Gimp, the "Histogram" dialog applies to the selection, so the pixel count displayed is the pixels in the selection (weighted by their selection level):
In the image below the selection covers the black circle which has a 100px radius. The Pixels value is close to 100²*Pi (314000 instead of 314159).
The Count is the number of pixels between the two values indicated by the handles at the bottom of the histogram.
Of course the selection can have any shape and be obtained with various tools.
I assume PS has something equivalent.

AVISynth's ImageWriter is giving blank PNG files

Title says it all really.
BlankClip(length=100,width=1920,height=1080,pixel_type="RGB32",fps=60,color=$ff0000)
\ .ImageWriter("frames/%05d.png",type="png")
Expected result: 100 red images
What I got: 100 transparent images
I've tried the internal ebmp format, and that does give red images, but the "real thing" will have a transparent background and this is flattened to black. That aside, the frames are 7MB each which is just silly (real thing has 5-digit numbers of frames).
Any ideas?
Since you select "RGB32" format for BlankClip, you should provide the alpha channel in "color" parameter as well.
Apparently it's in ARGB format, so you should set it to $ffff0000 (first "ff" is for full opaqueness).

Set a wxImage to a specific wxColor

Is there a way to set every Pixel of a wxImage to a specific wxColour?
I am looking for a simpler way then to iterate over the pixels.
Maybe there's some built in fucntionality in wxImage already?
You can use method wxImage::SetRGB:
wxImage::setRGB(const wxRect &rect, unsigned char red, unsigned char green, unsigned char blue)
which sets the colour of the pixels within the given rectangle. But this method does not affect pixels alpha value (if the image has alpha channel).
On the other hand, you can convert your image to wxBitmap and fill it with desired colour using wxDC (or just create empty bitmap, fill with the colour and then convert to wxImage). Here is the example:
wxBitmap bitmap(my_wxImage_instance);
wxMemoryDC memdc;
memdc.SelectObject(b);
memdc.SetBackground(*wxGREEN_BRUSH);
memdc.Clear(); //fills the entire bitmap with green colour
memdc.SelectObject(wxNullBitmap);
my_wxImage_instance = wxBitmap(bitmap); //optionally
wxMemoryDC description.
In addition to the (good) answer by #nnatarr, you can also use wxImage::Clear() to set the image to any grey colour, including black or white.

Lesscss: Why spin(#000,180) is returning #000?

I need to know how to get the inverse color by lesscss.
Example: I have #000, i need #FFF.
And i need the detail explanation of spin(). And necessary links where i can see a color wheel where i can understand how spin() works.
Thanks.
Why it is not working as you expect
The spin() function only deals with hue (color), not value (grey scale changes are a value change). Take a look at Figures 9 and 10 on this page from North Carolina State University's site. Those figures help show the difference. The spin() function is rotating only in the two dimensional space of the hue circle of color, not along the axis of the third dimensional space dealing with saturation; i.e. the gray scale itself, which is what differentiates white from black, both of which have no color saturation).
This is why on the LESS site we read of spin() (emphasis added):
Note that colors are passed through an RGB conversion, which doesn't
retain hue value for greys (because hue has no meaning when there is
no saturation)
And
Colors are always returned as RGB values, so applying spin to a grey
value will do nothing.
Getting what you want (Color Inversion)
See #seven-phases-max's answer.
The spin function changes the Hue property of a colour. Shades of grey (incl. white and black) are achromatic colours (i.e. they have the same "undefined" hue value).
To simply invert a colour use either difference function:
difference(white, #colour)
or the simple colour arithmetic:
(#fff - #colour)