I want Blur Image Program code in java please help
I found some replies thanks
Description about this problem is as follows:-
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[3][3] in the output image would be average of following 9 points in the source image ( data [2][2], data [2][3], data [2][4] , data [3][2], data [3][3], data [3][4], data[4][2], data [4][3], data [4][4] ). 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) { if(radius<0 || radius>=i.rows || radius>=i.columns) 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; for(x=p-radius;x<=p+radius;x++) { if(x<0||x>=i.rows) continue; for(y=q-radius;y<=q+radius;y++) { 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