I hope you can help me, my code tries to identify if an image is symmetrical or not (assuming that the image is being compared in half on the X axis - left side with the right side)
Description of my code:
1.- I have a "nested for" that runs from the pixel at position (0,0) to ((getWidth / 2), getHeight), identifying its RGB color with alpha 255. => (X, Y)
2.- For each coordinate of the pixel traversed in the nested for, I create the coordinate of the pixel in the same position, located in the other half of the image (this part is correct) in the following way: "Symmetry_X = ((getWidth - (xi + 1)) + 1); ", I get your RGB code with alpha 255. => (Symetry_X, Y)
3.- My problem is, how do I compare the RGB code of each initial pixel (the one that runs through the nested for) with the RGB of the created coordinate. => RGB-Alpha (X, Y) <===> RGB-Alpha (Symetry_X, Y).
4.-I am giving you the solution as follows: Sum of the RGB and Alpha values of both pixels and comparing the values of both summations (each pair of pixels) in an if, which determines if it is symmetric or not. (Is that correct? In what other way, perhaps more simple, can I give you a solution?).
BitmapDrawable drawable = (BitmapDrawable) imgviewREXBlancoNegro.getDrawable(); Bitmap bitmap = drawable.getBitmap(); int getWidth = bitmap.getWidth(); int getHeight = bitmap.getHeight(); int color1,color2,Simetria_X; for (int xi = 0; xi <= (getWidth/2); xi++) { for (int yi = 0; yi <= getHeight-1; yi++) { int coordenada = bitmap.getPixel(xi, yi);// pixel int r = Color.red(coordenada); int g = Color.green(coordenada); int b = Color.blue(coordenada); int alpha = Color.alpha(coordenada); color1=r+g+b+alpha; Symmetry_X=((getWidth-(xi+1))+1); int coordenada1 = bitmap.getPixel(Symmetry_X, yi);// pixel int r1 = Color.red(coordenada1); int g1 = Color.green(coordenada1); int b1 = Color.blue(coordenada1); int alpha1 = Color.alpha(coordenada1); color2=r1+g1+b1+alpha1; if(color1!=color2){ LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.activity_mini_mensaje, (ViewGroup) findViewById(R.id.miniContenedor)); TextView text = (TextView) layout.findViewById(R.id.tvMensaje); text.setText("It is symmetrical"); Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); return; }else{ LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.activity_mini_mensaje, (ViewGroup) findViewById(R.id.miniContenedor)); TextView text = (TextView) layout.findViewById(R.id.tvMensaje); text.setText("It is not symmetrical"); Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); } } }
https://stackoverflow.com/questions/67443455/buy-2-pixel-rgb-colors-to-identify-if-the-image-is-symmetrical-or-not May 08, 2021 at 10:08AM
没有评论:
发表评论