A list,

RGB(red,green,blue) color space is the most common use of display systems (computers, television, etc., are RGB color space for image display). Generally speaking, computers and TELEVISIONS use three electron guns to emit electron beams of R component, G component and B component respectively, so as to excite the phosphors of RGB three colors on the screen, so as to emit pixels of different colors and brightness, and then compose an image. It is obvious that RGB color space makes use of the principle of superposition of three primary colors in physics to produce various colors. In RGB color space, the attributes of R, G and B components are independent. In other words, RGB colors can be expressed as (Red, Green, Blue). Among them, the smaller the value of each component, the lower the brightness. The greater the value, the higher the brightness; For example, (0,0,0) represents black, and (255,255,255) represents white; RGB color space said color format RGB565, RGB555, RGB24, RGB32, etc.; RGB565 uses 16 bits to represent a pixel: 5 bits to represent R, 6 bits to represent G, and 5 bits to represent B. RGB555 is another 16-bit representation of a pixel: 5 bits for each RGB component; The remaining digit is unused; RGB24 uses 24 bits to represent a pixel: 8 bits to represent each RGB component; This is the most common; RGB32 uses 32 bits to represent a pixel: 8 bits to represent each RGB component; The remaining eight bits are the alpha channel, which is used to indicate the “transparency” of the image. Note: On some systems, the remaining 8 bits are not used; RGB color space is called device-related color space, because different scanners scan the same image, will get different color image data; Different types of monitors display the same image, there will be different color display results. The RGB space used by the display and scanner is different from the CIE 1931 RGB true tri-color table color system space, which is device-independent color space.

Ii. Source code

clear all; close all; clc;
A = double(imread('bird_small.tiff')); Dim = size(A,1); % number of lines k =16; % means = zeros(k,3); % Initialize means to randomly-selected colors in the original photo.
rand_x = ceil(dim*rand(k, 1)); % initial means is random number of k rows and k columns as clustering center rand_y =ceil(dim*rand(k, 1));
for i = 1:k means(i,:) = A(rand_x(i), rand_y(i), :); % Find the initial clustering center end in the imagefor itr=1:100
    s_x=zeros(k,3);
    s_ind=zeros(k,1);
    for i=1:dim
        for j=1:dim
            r=A(i,j,1); g=A(i,j,2); b=A(i,j,3);
            [val ind]=min(sum((repmat([r,g,b],k,1)-means).^2.2));
            %repmat(A,k,1S_x (ind,:)=s_x(ind,:)+[r,g,b]; s_ind(ind)=s_ind(ind)+1;
        end
    end
    for ii=1:k
        if s_ind(ii)>0
            s_x(ii,:)=s_x(ii,:)./s_ind(ii);
        end
    end
    d=sum(sqrt(sum((s_x-means).^2.2))); % Calculated distanceif d<1e-5
        break
    end
    means=s_x;   
end
means = round(means);
itr

figure; hold on
for i=1:k
   col = (1/255).*means(i,:);
   rectangle('Position', [i, 0.1.1].'FaceColor', col, 'EdgeColor', col);
end
axis off
large_image = double(imread('bird_large.tiff')); figure; imshow(uint8(round(large_image))); large_dim = size(large_image,1);
for i = 1:large_dim
    for j = 1:large_dim
        r = large_image(i,j,1); g = large_image(i,j,2); b = large_image(i,j,3);
       
        large_image(i,j,:) = means(ind,:);
    end 
Copy the code

3. Operation results



Fourth, note

Version: 2014 a