天天看點

RGB圖像中三個通道的每個灰階值的像素個數

群上有位朋友說需要列舉RGB圖像中三個通道的每個灰階值的像素個數,在這裡貼一下代碼。 

圖檔:pc01.bmp

RGB圖像中三個通道的每個灰階值的像素個數
dev_clear_window() 
read_image (Image021,'L:/Halcon test/fruit/pc01.bmp') 
get_image_size (Image021, Width, Height) 
dev_open_window_fit_image (Image021, 0, 0, Width, Height, WindowHandle) 
gen_rectangle2 (ROI_0, 515.6, 935.599, rad(-90), 15.6, 4.8) 
decompose3(Image021, Image021R, Image021G, Image021B) 
rgb1_to_gray(Image021,Image021gray) 
dev_display(Image021R) 
stop() 
gen_rectangle1 (ROI_0, 170.5, 51.5, 426.5, 661.5) 
reduce_domain(Image021R,ROI_0,ImageReduced) 
threshold (ImageReduced, Regions, 11, 152) 
gray_histo(Regions, Image021R, AbsoluteHisto, RelativeHisto) 
intensity(Regions, Image021R, Mean1C021R, Deviation1C021R) 
disp_message (WindowHandle, '平均R通道值為' + Mean1C021R + ',偏差' + Deviation1C021R, 'windows', 70, 70, 'red', 'true') 
disp_continue_message (WindowHandle, 'black', 'true') 
stop() 
           
RGB圖像中三個通道的每個灰階值的像素個數

區域的像素灰階值平均值 

圖檔:1.jpg

RGB圖像中三個通道的每個灰階值的像素個數
RGB圖像中三個通道的每個灰階值的像素個數

AbsoluteHisto變量的部分像素數量。

繼續閱讀