Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Blur Image

I found some replies thanks

In the Blur Image problem, you are given an image and you have to compute an image blurred as per the given parameters. If radius is r then for a pixel at the data[x][y] in the output image, you would have to take an average of all pixels surrounding data[x][y] in radius r in the source image. For example if the radius 1, then data in the output image would be average of following 9 points in the source image ( data , data , data  , data , data , data , data, data , data  ). Similarly, for radius 2, you would taking average of up to 25 points for each pixel (and for radius 3, average of up to 49 points).
Note that averaging would be done individually for each R, G and B component i.e. each of R and G and B components should be separately averaged for calculating the result pixel color
Constraints
 Each data point in the image is in RGB Format (integer value up to 0xFFFFFF), if not return null.
 Radius r has to be less than both rows or column in the source image, otherwise return null.

the code i written is

```public image blur_image(image i, int radius) {

return null;
image o=new image();
o.rows=i.rows;
o.columns=i.columns;
o.data=new int[o.rows][o.columns];
int sr,sg,sb,x,y,d=0;
for(int p=0;p<i.rows;p++)
for(int q=0;q<i.columns;q++)
{
if( i.data[p][q]<0x000000 || i.data[p][q]>0xffffff)
return null;
d=0;
sr=0;
sg=0;
sb=0;
{
if(x<0||x>=i.rows)
continue;
{
if(y<0||y>=i.columns)
continue;
sr=sr+((i.data[x][y] >> 16)&0xff);
sg=sg+((i.data[x][y] >> 8)&0xff);
sb=sb+((i.data[x][y])&0xff);
d++;
}
}
sr=sr/d;
sg=sg/d;
sb=sb/d;
o.data[p][q]=(((sr<<8)|sg)<<8)|sb;
}
return o;

}```

Format of class image is

```public class image {
public int[][] data;
public int rows;
public int columns;
}```

I want you guys to help me in testing the code whether it is feasible solution for given problem or not

Thanks  Reply With Quote

3. ## Re: Blur Image

That will be £500 please Jokes aside, what code do you have so far?

// Json  Reply With Quote

4. ## Re: Blur Image

Here's a simple blurring algorithm:

2. Average the RGB values of all 9 pixels and stick them in your current pixel location
3. Repeat for every pixel

Note: Remember not to store your "averaged" pixels into the same picture as the non-averaged picture, or it won't blur corrrectly. Also, you'll have to figure out a way to handle the edge pixels. You can either keep them the same, or take a smaller box to sample pixels from.  Reply With Quote

5. ## Re: Blur Image

Interesting, I might give this a go later on for funsies // Json  Reply With Quote

6. ## Re: Blur Image

Here's code that ignores the edges. It also lets you set the blur level (how many times it's run).

```public static Color[][] blur(Color[][] image, int blurLevel)
{
Color[][] blurred = image.clone();
for (int t = 0; t < blurLevel; t++)
{
for (int i = 1; i < blurred.length - 1; i++)
{
for (int j = 1; j < blurred.length - 1; j++)
{
int blue = image[i - 1][j - 1].getBlue()
+ image[i - 1][j].getBlue()
+ image[i - 1][j + 1].getBlue()
+ image[i][j - 1].getBlue() + image[i][j].getBlue()
+ image[i][j + 1].getBlue()
+ image[i + 1][j - 1].getBlue()
+ image[i + 1][j].getBlue()
+ image[i + 1][j + 1].getBlue();
blue /= 9;
int red = image[i - 1][j - 1].getRed()
+ image[i - 1][j].getRed()
+ image[i - 1][j + 1].getRed()
+ image[i][j - 1].getRed() + image[i][j].getRed()
+ image[i][j + 1].getRed()
+ image[i + 1][j - 1].getRed()
+ image[i + 1][j].getRed()
+ image[i + 1][j + 1].getRed();
red /= 9;
int green = image[i - 1][j - 1].getGreen()
+ image[i - 1][j].getGreen()
+ image[i - 1][j + 1].getGreen()
+ image[i][j - 1].getGreen()
+ image[i][j].getGreen()
+ image[i][j + 1].getGreen()
+ image[i + 1][j - 1].getGreen()
+ image[i + 1][j].getGreen()
+ image[i + 1][j + 1].getGreen();
green /= 9;
blurred[i][j] = new Color(red, green, blue);
}
}
image = blurred.clone();
}
return blurred;
}```  Reply With Quote

7. ## Re: Blur Image

You didn't set the radix (aka. base). To use parseInt on a hex number:

`Integer.parseInt("FF3a20056",16);`  Reply With Quote

8. ## Re: Blur Image

... I'm slightly confused at what it is you want.

To get a hex String to into an int:

`Integer.parseInt("1234AB",16);`

To get an integer back into a hex string:

`Integer.toHexString(123);`

To input a number as a hex, add 0x before it:

`int num = 0x62; // num = 98`

fyi, 98 is 0x62, not 0x68. Also, on the computer, all numbers are stored in binary because that's all the computer can really understand. The higher-level abstraction is what's displaying that number as decimal or hexadecimal, so it doesn't matter whether you put 0x62 into an int variable or 98 into an int variable they will have the same value.  Reply With Quote

9. ## Re: Blur Image

Sorry, I still don't understand what you want. Do you want a String hex output? The int data type doesn't matter whether it's in decimal, hex, octal, or binary. They all represent the same value. The default action for Integer.toString() is to return the decimal format for that value. You must use Integer.toHexString() in order to get a string representation of the hex value.

```System.out.println(0xa); // this will print out "10"
System.out.println(Integer.toHexString(0xa)); // this will print out "a"```

0xa is understood to be an integer, not a string.  Reply With Quote

10. ## Re: Blur Image

If you want to re-combine the 3 RBG byte values into an int, simply shift the values into the appropriate spots and add. I've said it before, it doesn't matter whether there's a hex or a decimal or any other random base stored inside of an int, they all hold the same value. If you want that int to be displayed as a hex string, you must use the Integer.toHexString() or some sort of equivalent method.

```// put red byte, green byte, and blue byte into lower 3 bytes of an int
int red = 0x62;
int green = 0x00;
int blue = 0x96;
int rgb = (red << 4) + (green << 2) + blue;
System.out.println(Integer.toHexString(rgb)); // print out as a hex
System.out.println(rbg); // print out the same value as a decimal```  Reply With Quote

11. ## The Following User Says Thank You to helloworld922 For This Useful Post:

prakash (December 31st, 2009)

12. ## Re: Blur Image

Hey prakash i think u came through this question in

ASPIRATIONS 2020

Man Your code will be evaluated by Server and the test cases provided in main function are just for our verification and server tests ** public image blur_image(image i,radius r) ** function with different inputs

no one ( upto my knowledge ) has not got solution for that problem and im searching for it from approximately 2 months

and also each line of your code will have marks awarded by server so dont get worried about the problem  Reply With Quote

13. ## The Following User Says Thank You to psrkiran For This Useful Post:

prakash (December 31st, 2009)

14. ## Re: Blur Image

helloworld922
Thanku for everything.
Truly belive me. i learned best of java. and it was awesome time to be with u.
all i have to say is THANKUUUUUUUU     Reply With Quote