Determining Darkest and Lightest Color - vb.net

I have an image loaded into a picture box, and need some help with a way to detect the Darkest color present in the image, the Lightest color present, and the color which is in the middle.
The point being so that I can refine my heightmap generator based on these 3 colors.
I'm thinking of looping through each X,Y coordinate within the picture box, set the darkest and lightest value, and overwrite those values if a darker/lighter one is found.
The part I'm stuck at is determining what exactly I can use to check how dark or light a spot within the picture box is. RGB?
Any guidance is appreciated.

Related

How to compare pixel colour with pixel by pixel using CGPoint in UIImage

In my project I need to remove selected colour like wand tool.For this i was used flood fill algorithm(Flood fill).but it was not working properly for colour comparison(pixel by pixel).can any one suggest the solution.
In below images i need to remove background colour only(expected).
output Result.
can any one please help me with code Or example.

Remove selected color from image (grayscale graphic)

enter image description here
enter image description here
Hi guys! I have the following task: I must paint the black and white house, leaning to a result as the colored one.
I figured out, there must be a way to somehow "remove" the white color, so there is only the black outlines left. From there I will make an underlayer and will insert color/materials etc.
The hard part and the essential in my question is: The black outlines are ranging from true black to very light grey. Is there a way I can somehow delete all white (0,0,0) pixels and for the others: the more "black" they have, the more opacity they get. So a grey pixel with a value around (126,126,126) will be left, but with a 50% opacity.
have you tried, copying the same image on top of the original image, change the copied image blending mode to overlay, use the select tool on the white area, and then click the select tab on top menu, from that tab click select similar,so you have all the white area selected, then select the original layer, and then erase, you can also erase delete the copied image. Good Luck!
Yes you can,
Open "Select" menu and choose "Color Range", it will open a dialog box, inside that box you can choose from the drop down at the top if you want to select Reds, Yellows, Greens, etc. or you can select Sampled Colors with the eyedropper tool, so you can select the white color from anywhere at the image then you can handle the color range sensitivity from the slide bar called Fuzziness, the lower number is the lower range of white color and vise versa :)
As Ahmed Alaa said, use the "Color Range" tool, but for coloring in black and white images, see if my Youtube tutorial can help.
-https://www.youtube.com/watch?v=4My4dVU5iUE
P.S. Sorry this post is bad, i'm new-ish.

How to revert back to not require rasterize

I used to be able to color any Text, shape, or image by just selecting the particular layer and use pain bucket tool for example. Not sure what I clicked, but recently when I try to do the same; I always get the following message:
"This type Layer must be rasterized before proceeding. Its text will
no longer be editable. Rasterize the type? "
I do not want to rasterize. Can I know how to revert back to the normal setup where I can do the coloring without the need for rasterize please.
It also seems to mess around with my selection.
For example - I have a circle shape in the middle with transparent background.
I used to be able to go Select>All followed by Select>Inverse and it will select the circle shape.
But now it selects the entire canvas when I select all but returns the following error when I Select>Inverse
"Warning No Pixels were selected".
You may not be able to color a vector object with paint bucket tool. Instead, can you try using the color option in the blending mode. That will retain the vector property and also apply the color.
The following applies to PS-CS6
In the layers palette,
= Right click on the layer > Blending Options > Select Color Overlay

How to create letterpress effect?

I'm looking to implement something like the famous "letterpress" effect in my application. Here's what I'm talking about: (just a quick example made in PShop)
As you can see, it looks like it's pressed into the background. I wonder if it's possible to do something like this on the Mac dynamically. Is there a way? Thanks!
You can do the gradient fill portion of the text using the code I provide in this answer. Check the coordinate space first, because I described that for the iPhone, which has an inverted Y axis when compared to the Mac's normal Quartz coordinates.
The text is first used to create a clipping path, and the gradient is drawn within that path.
As far as the internal shadow, you might be able to draw this after the gradient is drawn by using CGContextSetShadowWithColor() with an appropriate downward offset and black color, then drawing the text again using just the stroke of the text. deanWombourne has some sample code for a similar task in his answer here.
Draw the text with a normal font to create a black and white bitmap of the text.
Draw another image that is is the same size and completely filled with the gray-to-white gradient you have above.
Create a completely white image with the same size as your other images.
Draw your back and white text image (1) onto the white image (3) with NSCompositeDestinationOut.
This gives you a white image with your text cut out.
Draw the white image with the text cut out on top of the gradient image and apply a shadow while drawing.

Rectangles & Parsing in vb.net

This is kinda....a two part question. The first one is much more important than the second one, both of these are in the same project, and in vb.net.
How can I constrain the bounds of a rectangle object, which is controlled by a mouse, so it cannot be drawn outside a PictureBox? It is kindof a standard lasso control, the user can click and drag and it will draw a box from the initial click point to the mouse's current location. The starting point is at (rectX,rectY), and the box is drawn to the bottom right using rectDimX and rectDimY (to set the width and height) to see how much of a change has occurred with the mouse. Basically, its what you get with a click and drag on a Windows desktop. The issue here is that the rectangle is able to be drawn outside the PictureBox it is being drawn on, and the next part of the code attempts to reference this location, and then fails with an OutOfMemory exception. This leads me to my second question:
How can I make the rectangle draw in more than the fourth quadrant, which is only positive numbers? If it goes anywhere else, it does not show the rectangle, though it does still have the correct values. I know i could code this four times based on starting location and mouse location, but that would be a huge hassle and a rewrite of the whole rectangle code.
Is there an easy solution for either of these? The first one is a much bigger hassle, as it will be very time consuming if there is no easy way.
Thanks for the help!
For the first part of your question, even if the user drags the mouse beyond the edge of your picture box, you don't have to use those coordinates for your drawing routine. Simply do something like
If (DrawingPoint.X > PictureBox.Right)
DrawingPoint.X = PictureBox.Right // Right-hand limit of picture box
End If
And similar for the Y direction.
As for the negative numbers while drawing, you want to translate screen coordinates to client area coordinates. Have a look at ScreenToClient and ClientToScreen.