0

public BufferedImage processImage(BufferedImage img){ int height =img.getHeight(); int width = img.getWidth();

What does this code do?

30th May 2019, 11:43 AM
Stefano
16 ответов
+ 4
Stefano hi, your code is seems incomplete. But as looking at the syntax this is an program of image processing in which you have created an processImage function which is used to process image Any image is firstly stored in an BufferedImage in Java coding this buffer is an memory location in computer which store image every time we need to clear the buffer for next image pixel. The lines inside the function is of taking width and height of the image img.getHeight() is take the height of the image and img.getWidth() is used to take the width of the image. If you want to ask any further query ping me I'll loved to answer Have some 🍎 🍎 🍎 🍎
30th May 2019, 11:48 AM
DishaAhuja
DishaAhuja - avatar
+ 3
Stefano it is used to read the image in which We want to do some manipulation of color or size or rotate etc for that first we need to read the image which is done by your mentioned code snippet look my complete code to understand that can't be executed on sololearn but try it on any Java ide https://code.sololearn.com/cA3CCDTV4Zgi/?ref=app Have some 🍎 🍎 🍎 🍎 🍎
30th May 2019, 11:52 AM
DishaAhuja
DishaAhuja - avatar
+ 3
Stefano these is one of my old code which is used to find color component preset in the image. For find any color component we used RGB color values, this RGB color values combination is make all color and during the study of image processing some constant are derived through HSV and HSI model of image and from that this constant values comes. We used this constant values to get different combinations of color which is called different colors components. But if you started to learn digital images processing them first read all algorithms and derived it by your own to get more knowledge have these some more 🍎 🍎 🍎 🍎 🍎
30th May 2019, 11:59 AM
DishaAhuja
DishaAhuja - avatar
+ 3
Stefano in the invert image we have to add some black color pixel in the sample image space and then we have to negate that pixel value from the sample image pixel value then the processing in computer define the value come after the negation of image. In general each pixel value is get negated by applying an filter matrix initially then that image is converted to negative image
30th May 2019, 12:09 PM
DishaAhuja
DishaAhuja - avatar
+ 3
Stefano that is processed by computer so without execute the code we can't assume any value as to calculate that without execution first tell me the image matrix, then tell me the filter matrix, then I'll be able to calculate the main output matrix with the help of dot product of matrix then this matrix every element is for product by the constant value came from derivation then the new inverted image pixel value will be came as output so execute it in computer that's why I give you the logic and the code by which you can do that and read the algorithm to match the answer that will give you the approximate best answer of new inverted image Without the information of matrix we can't calculate the pixel values of any image
30th May 2019, 12:16 PM
DishaAhuja
DishaAhuja - avatar
+ 3
Stefano Here is your code explan public BufferedImage processImage(BufferedImage img){ //for getting height of image int height =img.getHeight(); for getting width of image int width = img.getWidth(); int i,k; //running for loop till width and one till height for(i =0;i<width;i++){ for(k=0;k<height;k++){ //old color value of sample image before Coversion Color old = new Color(img.getRGB(i, k)); //changing value of r, g, b with multiply by an constant value so that new pixel can be generate int r = (int)(old.getRed()*0.25); int gr = (int)(old.getGreen()*0.5); int b = (int)(old.getBlue()*0.25); //add this new pixel in sample image pixel Color nw=new Color(r+gr+b,r+gr+b,r+gr+b); // by this new sum pixel generate and set the new rgb value by setRGB() img.setRGB(i, k, nw.getRGB()); }} //it return the new generated image return img; } Thats is how your code is running
30th May 2019, 12:30 PM
DishaAhuja
DishaAhuja - avatar
+ 2
Stefano this is an theoretical problem which can be present in the text book the basic means of the code I have already explained, I can explain you theory but to type the whole concept here is not possible So please read the answer and if you found any difficulty ping me
30th May 2019, 6:59 PM
DishaAhuja
DishaAhuja - avatar
0
Thank you very much
30th May 2019, 11:49 AM
Stefano
0
Why is that so?
30th May 2019, 11:49 AM
Stefano
0
What would be the effect of changing the co-efficients 0.25,0.5 and 0.25 to 0.1, 0.6 and 0.3 in the code above?
30th May 2019, 11:56 AM
Stefano
0
I see.. You very helpful
30th May 2019, 12:01 PM
Stefano
0
Image negatives are a form of point/pixel based image processing. Given an RGB pixel with the value (128,75,180), What would the RGB pixel value be if its negated?
30th May 2019, 12:02 PM
Stefano
0
So what would be tge value?
30th May 2019, 12:11 PM
Stefano
0
public BufferedImage processImage(BufferedImage img){ int height =img.getHeight(); int width = img.getWidth(); int i,k; for(i =0;i<width;i++){ for(k=0;k<height;k++){ Color old = new Color(img.getRGB(i, k)); int r = (int)(old.getRed()*0.25); int gr = (int)(old.getGreen()*0.5); int b = (int)(old.getBlue()*0.25); Color nw=new Color(r+gr+b,r+gr+b,r+gr+b); img.setRGB(i, k, nw.getRGB()); }} return img; } Thats my code in full
30th May 2019, 12:11 PM
Stefano
0
Sorry for the inconvenience but am having an exam and that's like a compulsory question that i do not know the answer
30th May 2019, 12:12 PM
Stefano
0
Consider the code below carefully and then answer Q.1. public BufferedImage processImage(BufferedImage img){ int height =img.getHeight(); int width = img.getWidth(); int i,k; for(i =0;i<width;i++){ for(k=0;k<height;k++){ Color old = new Color(img.getRGB(i, k)); int r = (int)(old.getRed()*0.25); int gr = (int)(old.getGreen()*0.5); int b = (int)(old.getBlue()*0.25); Color nw=new Color(r+gr+b,r+gr+b,r+gr+b); img.setRGB(i, k, nw.getRGB()); }} return img; } Q. 1 a) What does the code above do? Why do you say so? (5 marks) b) What would be the effect of changing the co-efficients 0.25,0.5 and 0.25 to 0.1, 0.6 and 0.3 in the code above? (5marks) c) Image negatives are a form of point/pixel based image processing. Given an RGB pixel with the value (128,75,180), What would the RGB pixel value be if its negated? (5 marks)
30th May 2019, 6:49 PM
Stefano