⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 definecolor.m

📁 to define color of the image
💻 M
字号:
%Group member
%Tilaporn 4988037
%Nuttawan 4988140
%Ratchawit 4988158
%Pichittra 4988249
%Wisarat 4988251

function definecolor()
maxr=0;
maxg=0;
maxb=0;

[datafile,datapath]= uigetfile('*.*','choose an image');
if datafile
    datapathFile = strcat(datapath,datafile);
    x = imread(datapathFile);
    imshow(x);
    [rows col] = size(x);
    col = col/3;
    count_b = 0;
    count_w = 0;
    
    for i=1:rows
        for j=1:col

                if (x(i,j,1) == 0) && (x(i,j,2) == 0) && (x(i,j,3) == 0)
                    count_b = count_b + 1;
                end
                if (x(i,j,1) == 255) && (x(i,j,2) == 255) && (x(i,j,3) == 255)
                    count_w = count_w + 1;
                end
        
        end
    end
    
    x1 = x(:,:,1);
     x2 = x(:,:,2);
      x3 = x(:,:,3);
      
      [red , a] = imhist(x1);
       [green , b] = imhist(x2);
         [blue , c] = imhist(x3);
         
         red(1) = red(1) - count_b;
         red(256) = red(256) - count_w;
         green(1) = green(1) - count_b;
         green(256) = green(256) - count_w;
         blue(1) = blue(1) - count_b;
         blue(256) = blue(256) - count_w;
         
         meanR = mean(mean(x1));
         meanG = mean(mean(x2));
         meanB = mean(mean(x3));
         
         
         if (meanR >= meanG)&&(meanR >= meanB)
            result = 'RED';
            n = meanR - meanG ;
            m = meanR - meanB;
            if (meanG >= meanB) &&( n <=10) 
                result ='ORANGE';
            end
            if (meanG >= meanB)&&(n<=1)
                result = 'YELLOW';
            end
            if (meanB >=meanG)&&(m<=1)
                result = 'PINK';
            end
         end  
         if (meanG >= meanR)&&(meanG >= meanB)
             result = 'GREEN';
             o = meanG - meanR ;
             if (meanG >= meanB)&&(o<=1)
                result = 'YELLOW';
             end
         end
         if (meanB >= meanR)&&(meanB >= meanG)
            result = 'BLUE';
            p = meanB - meanR;
            if (meanR >= meanG)&&(p<=10)
                result = 'MAGENTA';
            end
         end
      
            msgbox(strcat('result  color is ','...',result));
                  

else
    hd_error = errordlg('Please select a filename');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -