Question
You goal in this project is two-fold: Create a java program that will print out the following statistics about an image (gray-level image of one
You goal in this project is two-fold:
- Create a java program that will print out the following statistics about an image (gray-level image of one channel). A color image must be converted to gray level using the utility functions provided to you.
- Overall mean of the image
- Overall variance of the image
- The dynamic range of the image
- As an application of the mean, you will also create a function that will take an image, a top-left corner coordinate, a block size and a sub-block size and return an image that has the passed block blurred (by blurring the subblocks within it)
- For example, you would specify the block at I,J of a given block size (for example 32). You will then identify the block and break it into sub-blocks (for example of size 4). For each subblock, you will then compute the mean and replace all the pixels in the subblock by their mean.
- The subblocks will be blurred because you replaced every pixel with its mean.
- You can access the subblocks with a double loop that starts at I,J and increment by the subblock size
for(int i = I; i < I + BlockSize; i += subblockSize) {
for(int j=J; j < J + BlockSize; j += subblockSize) {
Identify subblock
Calculate mean
Replace each pixel by the mean with proper cast and clipping
}
}
I already know how to do the first part of the assignment that asks to calculate mean, variance, and dynamic range. What I need help with is the second part that asks to identify a sub-block and blur each pixel in the sub-block using the mean of the sub-block. I don't know how to access the pixels in the sub-blocks.
This is the function I'm using to blur the image, but it doesn't blur the image correctly.
public static BufferedImage blurImage(byte[][] imageArray, int I, int J, int blockSize, int subBlockSize) { byte[][] subBlock = new byte[subBlockSize][subBlockSize]; int subBlockMean = 0; for (int i = I; i < I + blockSize; i+= subBlockSize) { for (int j = J; j < J + blockSize; j += subBlockSize){ for (int k = 0; k < subBlockSize; k++) { for (int l = 0; l < subBlockSize; l++) { System.arraycopy(imageArray,i,subBlock,0,subBlockSize); subBlockMean = calculateMean(subBlock); imageArray[k + i][l + j] = (byte)ImageIo.clip(subBlockMean); } } } } BufferedImage blurredImage = ImageIo.setGrayByteImageArray2DToBufferedImage(imageArray); ImageIo.writeImage(blurredImage, "jpg", "blurredImage.jpg"); return blurredImage;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started