splitting an RGB image to R,G,B channels - python -


I am working on image processing, I want to know whether this code splits colorful image into different channels Will not or I do not mean because when I tried to give me an image which is reading me, then give me blue, green, red values, and mean value too. When I try to add it to the list, and try to print it, then the list only contains zero.

This is my code:

  b, g, r = cv2.split (re_img1) ttl = re_img1.size b = sum (b) / ttl g = sum (G) / ttl r = yoga (r) / ttl b_man 1.append (b) g_map 1.apend (g) r_man1 .append (r)   

re_img1 < / code> is a resized image (i.e. 256x256). The image can be anything and I am using the same code in 2 different functions, and I am facing a single problem.

Any suggestions are welcome! thank you in advanced!

If I understand you well then you try to calculate the mean of each RGB channel Are there. There are 2 problems with your code:

  1. ttl should be split down from 3 because otherwise it is the number of pixels X channels (ex: 256X256 for RGB ), Which will be 196608)
  2. In your code, b, g, and r are actually numpy.ndarray Type, so that you should use the appropriate methods to manipulate them, ie ndarray.sum . Make the float a float, otherwise you will lose the decimal, because the degrees of 2 ints will give you an integer.

      import cv2 import np as np re_img1 = cv2.imread ('re_img1.png') b, g, r = cv2 esplelete (reimil 1) ttl = reiming 1 size / 3 To get the number of image by # 3, PIXELS "b", g, and r are actually numpy.ndarray types, so that you need to use the appropriate method to sum all the array elements "B" = Float (NPSS (B)) / TTL # Convert float as, B, G, and R otherwise G = float (np.sum (g)) / ttl r = f Lot (NP SUM (R)) / TTL B_Menya 1 = List () G_Im1 = LIST () R_MEN_11 = LIST () B_MEN 1.append (B) G_IAN 1.append (G) R_MEN 1.append (R) < / code>    

    Hope is useful for you. Cheers!

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -