Kernel Image Processing with a buffered image - java

So I have a given 3 by 3 array mask[][] and a buffered image. I must loop through the position[row][column] of the buffered image, and I must place the middle pixel of the mask to the current buffered image position. Then for each color component , I must multiply the value of the color component in the image that falls under the mask to the corresponding mask value, and add all nine values together. Lastly I combine the three color values to get the RGB color of the pixel.

Related

How to calculate distance from a pixel in the CIELAB color space to its corresponding Maximum RGBY

I have a RGB image and i converted it into CIELAB color space. the next step is, I need to compute the corresponding R,G,B,Y values respectively from the the CIELAB image, which means from the CIELAB image i should get one image for Red, Green, Blue,Yellow after computing their corresponding pixel values from the CIELAB image.
so, for each pixel in the CIELAB image i am getting its value on the A-Axis and the B-Axis, but what i do not know how to do is, how to compute the distance from the pixel value on the a-Axis and the B-Axis to the Maximum red vlaue for an example. in other words, if the pixel in the CIELAB color space at row = 3 and col = 3 has A-AxisValue = 100 and B-AxisVal = 60, then how can I calculate the distance from this pixel to the Maximum Red color value on the CIELAB color space.
the question in other words, how to clculate the distance from a current pixel in the CIELAB color spce to the maximum R,G,B and Y in the same color space? to solve this, i need the maximum coordinates of R,G,B,Y on the CIELAB color system

why the grayscale image has 3 channels

i am performing operations on a grayscale image, and the resultant image of these operations has the same extension as the input image. for an example if the input image is .jpg or .png the output image is either .jpg or .png respectively.
and I am converting the image into grayscale as follows:
ImgProc.cvtColor(mat, grayscale, ImgProc.COLOR_BGR2GRAY),
and I am checking the channels count using:
.channels()
the problem is when I wnat to know how many channels the image contain, despit it is a grayscale image, i always receive umber of channels = 3!!
kindly please let me know why that is happening
The depth (or better color depth) is the number of bits used to represent a color value. a color depth of 8 usually means 8-bits per channel (so you have 256 color values - or better: shades of grey- per channel - from 0 to 255) and 3 channels mean then one pixel value is composed of 3*8=24 bits.
However, this also depends on nomenclature. Usually you will say
"Color depth is 8-bits per channel"
but you also could say
"The color depth of the image is 32-bits"
and then mean 8 bits per RGBA channel or
"The image has a color depth of 24-bits"
and mean 8-bits per R,G and B channels.
The grayscale image has three channels because technically it is not a grayscale image. It is a colored image with the same values for all the three channels (r, g, b) in every pixel. Therefore, visually it looks like a grayscale image.
To check the channels in the image, use-
img.getbands()

pixel's exact value from a JPG image in java

does anyone know how can I get the exact values from JPG image, for example: I have created an image that only contains values from 0 - 255, this image is on gray scale, that means : RGB values are exactly the same. In the other hand I exactly know the value from each pixel in each position, but when I use the getRGB() Im gettin values that does not match with the original values. Eg:
I have a '0' in the position [0][0] the getRGB() is returning a decimal number '13'; in the next position [0][1] I have a '1' but the getRGB() is returning a decimal number '13' too... So guys I know that these values can be because of the compression of the image. But anyone has an idea of what adjust I can make to get the correct values???
I will appreciate any help..
JPEG uses lossy compression algorithm: it sacrafices data precision to achieve better compression. So you can't get back the exact RGB values.
If you need to get back the exact RGB values, use PNG image format which uses lossless compression algorithms.
Also BufferedImage.getRGB() returns the pixel data quoting from the javadoc:
Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.
So if you have gray values in the range of 0..255, the RGB values returned by getRGB() will be in the range of 0...16777215 (16777215=0xffffff). The int returned by getRGB() is not the gray version but contains the RGB components (and the alpha if it has transparency).

Libary/method for loading a HDR/high-bittage image and accessing its pixel values?

Short;
I need to get the value of a specific pixel from a supplied high color depth image.
Details:
I am currently using Processing to make a Slit-scanning program.
Essentially, I am using a greyscale image to pick frames from an animation, and using pixels from those frames to make a new image.
For example if the greyscale image has a black pixel, it takes the same pixel in the first frame, and adds it to an image.
If its a white pixel, it does the same with the last frame.
Anything inbetween, naturally, picks the frames inbetween.
The gist is, if supplied a horizontal gradient, and a video of a sunset, then youd have the start of the sunset on the left, slowly transitioning to the end on the right.
My problem is, when using Processing, I seem to be only able to get greyscale values of
0-255 using the default library.
Black = 0
White = 255
This limits me to using only 256 frames for the source animation, or to put up with a pixaly, unsmooth end image.
I really need to be able to supply, and thus get, pixel values in a much bigger range.
Say,
Black = 0
White = 65025
Is there any Java lib that can do this? That I can supply, say, a HDR Tiff or TGA image file, and be able to read the full range of color out of it?
Thanks,
Ok, found a great library for this;
https://code.google.com/p/pngj/
Supports the full PNG feature set - including 16 bit greyscale or full color images.
Allows me to retrieve rows from a image, then pixels from those rows.
PngReader pngr = new PngReader(new File(filename));
tmrows = pngr.readRows();
ImageLineInt neededline = (ImageLineInt)tmrows.getImageLine(y);
if (neededline.imgInfo.greyscale==true){
//get the right pixel for greyscale
value = neededline.getScanline()[x];
} else {
//get the right pixel for RGB
value = neededline.getScanline()[x*3];
}
You simply multiply by 3 as the scanline consists of RGBRGBRGB (etc) for a full color image without alpha.

What does Graphics.setXORMode(Color) do in simple terms?

Here is what I read about it but cant understand exactly what it does:
One way to implement rubber-banding is to draw in XOR mode. You set
XOR mode by calling the setXORMode() method for a graphics context and
passing a color to it — usually the background color. In this mode
the pixels are not written directly to the screen. The color in which
you are drawing is combined with the color of the pixel currently
displayed together with a third color that you specify, by exclusive
ORing them together, and the resultant pixel color is written to the
screen. The third color is usually set to be the background color, so
the color of the pixel that is written is the result of the following
operation:
resultant_Color = foreground_color^background_color^current_color
I know how XORing works but don't know what the above paragraph means. Please elucidate it for me
It takes a color in and applies an XOR mask just like a regular XOR would a bit mask, except it is on the RGB colors, so it produces the color you pass in if it overlays a color with the same values or the inverse of that colors RGB and and color below its RGB if the values are different.
Just write some code and try it and it will be immediate evident what happens.

Categories

Resources