My initial task is to take a grayscale image in java, perform DCT over it (using block size 8X8) , write the DCT image. Then take the DCT image and then perform the inverse DCT over it to get back the original image.
Now the problem am facing here is , when each of the block undergoes DCT, the operation will result in many negative values and the values out of the grayscale range (for eg.,260).
How to write a grayscale image with negative values and the values out of the range? Is there any other operation need to be performed before writing the image so that all the values fall under the 0-255 range?
Related
Can IDCT give negative values after applying it to block based DCT channels?
I divided the gray image in 4*4 blocks and they took the 4*4 DCT of the blocks. Then using those blocks i created DCT channels. Each channel contained the spread of a frequency over the image.
Yes it can. The DCT is a sum of cosines, which have zero mean. So you may very well have nonzero pixels with negative weights only.
I'm getting all pixels' RGB values into
R=[],
G=[],
B=[]
arrays from the picture. They are 8 bits [0-255] values containing arrays. And I need to use Fourier Transform to compress image with a lossy method.
Fourier Transform
N will be the pixel numbers. n is i for array. What will be the k and imaginary j?
Can I implement this equation into a programming language and get the compressed image file?
Or I need to use the transformation equation to a different value instead of RGB?
First off, yes, you should convert from RGB to a luminance space, such as YCbCr. The human eye has higher resolution in luminance (Y) than in the color channels, so you can decimate the colors much more than the luminance for the same level of loss. It is common to begin by reducing the resolution of the Cb and Cr channels by a factor of two in both directions, reducing the size of the color channels by a factor of four. (Look up Chroma Subsampling.)
Second, you should use a discrete cosine transform (DCT), which is effectively the real part of the discrete Fourier transform of the samples shifted over one-half step. What is done in JPEG is to break the image up into 8x8 blocks for each channel, and doing a DCT on every column and row of each block. Then the DC component is in the upper left corner, and the AC components increase in frequency as you go down and to the left. You can use whatever block size you like, though the overall computation time of the DCT will go up with the size, and the artifacts from the lossy step will have a broader reach.
Now you can make it lossy by quantizing the resulting coefficients, more so in the higher frequencies. The result will generally have lots of small and zero coefficients, which is then highly compressible with run-length and Huffman coding.
I have an image whose RGB values for each pixel is stored in a 2-D array. Assuming I want to apply, a basic 3X3 averaging algorithm for smoothing the image. How can I implement such an algorithm using map-reduce paradigm.
Thanks in advance.
This took me a while to think in map reduce paradigm but anyways here it is -
Map Task
Input - (x-coordinate,y-coordinate,RGB value)
Output - 9 tuples which are these {(x,y,RGB),(x-1,y,RGB),(x-1,y-1,RGB),(x,y-1,RGB),(x+1,y-1,RGB),(x+1,y,RGB),(x-1,y+1,RGB),(x,y+1,RGB),(x+1,y+1,RGB)}
Reduce Task
The framework will sort all these tuples based on the keys(x-coordinate,y-coordinate) and rearrange them.So now for each pixel you have 9 RGB values of it's neighboring pixels. We simply average them in the reduce task and output a tuple ----> (x,y,avg_RGB)
So, basically instead of each pixel telling the RGB values of all its neighboring pixels for itself, it broadcasts it's own RGB value as pixel value of it's neighbors.
Hope this helps :)
When given an image such as this:
And not knowing the color of the object in the image, I would like to be able to automatically find the best H, S and V ranges to threshold the object itself, in order to get a result such as this:
In this example, I manually found the values and thresholded the image using cv::inRange.The output I'm looking for, are the best H, S and V ranges (min and max value each, total of 6 integer values) to threshold the given object in the image, without knowing in advance what color the object is. I need to use these values later on in my code.
Keypoints to remember:
- All given images will be of the same size.
- All given images will have the same dark background.
- All the objects I'll put in the images will be of full color.
I can brute force over all possible permutations of the 6 HSV ranges values, threshold each one and find a clever way to figure out when the best blob was found (blob size maybe?). That seems like a very cumbersome, long and highly ineffective solution though.
What would be good way to approach this? I did some research, and found that OpenCV has some machine learning capabilities, but I need to have the actual 6 values at the end of the process, and not just a thresholded image.
You could create a small 2 layer neural network for the task of dynamic HSV masking.
steps:
create/generate ground truth annotations for image and its HSV range for the required object
design a small neural network with at least 1 conv layer and 1 fcn layer.
Input : Mask of the image after applying the HSV range from ground truth( mxn)
Output : mxn mask of the image in binary
post processing : multiply the mask with the original image to get the required object highligted
i want to make an image scrambling using DCT in matlab. i used a grayscale image. i want to random dc with random value. how to set the DC coefficient of each block to a random
value 0-255 and leave all others??these are steps for experiment:Divide a gray image into 8x8 blocks;Perform DCT on each block;set the DC coefficient of each block to a random
value 0-255 and leave all others;Perform inverse DCT and restore the image;Compare the restored image with the original one
by SSIM.
thank you
The question is "how to set the DC coefficient of each block to a (given) value...". So the procedure you mention (DCT, set DC coefficient, then iDCT) should work. You would use Matlab's dct2 and idct2 functions.
However, from the DCT definition, the DC coefficient is the sum of the values of the pixels in each of your blocks; setting it to a random value and taking the inverse transform will produce a block that would be different from the original one only by a constant. That's no surprise because you are just changing the DC level. So you could skip the DCT/iDCT and directly add or subtract a random value to all pixels in each block.
But you can see that each block would look like the original one, except for a different luminosity; also, the boundaries between blocks would be quite visible, so the scrambling method could be easily reversed.