国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

數(shù)字圖像處理——灰度圖像(視頻)轉(zhuǎn)化偽彩色圖像(視頻)(含源代碼)

這篇具有很好參考價(jià)值的文章主要介紹了數(shù)字圖像處理——灰度圖像(視頻)轉(zhuǎn)化偽彩色圖像(視頻)(含源代碼)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

目錄

一,整體框架

指定圖像或視頻構(gòu)建索引表Byrgbgetindex

通過(guò)構(gòu)建的索引表進(jìn)行偽彩色轉(zhuǎn)換byindexgetrgb

通過(guò)函數(shù)映射進(jìn)行偽彩色轉(zhuǎn)換gray_differup2rgb

通過(guò)密度分割將灰度進(jìn)行映射midufenge

GUI界面 last

二,處理方法介紹

函數(shù)結(jié)構(gòu)

Byrgbgetindex

輸入內(nèi)容

Rgb_img

Bili

Junyuncha

Xianyancha

輸出內(nèi)容

Gray_Index

MissingNumbers

junhendijige

Xianyandijige

方法與流程

輸入?yún)?shù)規(guī)范化

構(gòu)建源顏色表

根據(jù)輸入的判定參數(shù)遍歷順序遍歷整個(gè)源顏色表?編輯?編輯?編輯

缺失灰度值用距離最近的灰度代替?編輯?編輯?編輯

將最終索引表按照灰度值升序排序?編輯?編輯?編輯

Byindexgetrgb

輸入內(nèi)容

輸入內(nèi)容

處理過(guò)程

Gray_differup2rgb

輸入內(nèi)容

輸出內(nèi)容

流程

Miudfenge

輸入內(nèi)容

輸出內(nèi)容

過(guò)程

三,GUI介紹

區(qū)域劃分

效果展示

四,源代碼

byrgbgetindex

byindexgetrgb

gray_differup2rgb

midufenge

last


一,整體框架

  1. 指定圖像或視頻構(gòu)建索引表Byrgbgetindex
  2. 通過(guò)構(gòu)建的索引表進(jìn)行偽彩色轉(zhuǎn)換byindexgetrgb
  3. 通過(guò)函數(shù)映射進(jìn)行偽彩色轉(zhuǎn)換gray_differup2rgb
  4. 通過(guò)密度分割將灰度進(jìn)行映射midufenge
  5. GUI界面 last
  • 二,處理方法介紹

    1. 函數(shù)結(jié)構(gòu)
      1. 輸入?yún)?shù)格式調(diào)整(將字符串轉(zhuǎn)化為數(shù)字,將彩色圖像轉(zhuǎn)化為灰度圖像)
      2. 處理參數(shù)返回結(jié)果
    2. Byrgbgetindex
      1. 輸入內(nèi)容
        1. Rgb_img
          1. 一張RGB圖像(兼容了灰度圖像
        2. Bili
          1. 根據(jù)自定義標(biāo)準(zhǔn),篩選出最終顏色的鮮艷與均勻占比
          2. 1/(bili+1)為鮮艷顏色
        3. Junyuncha
          1. 篩選顏色用到的自定義評(píng)判標(biāo)準(zhǔn),GValue-GrayValue小于junyuncha的認(rèn)為此顏色滿足均勻標(biāo)準(zhǔn)。
          2. 經(jīng)過(guò)實(shí)踐junyuncha設(shè)置為10-20效果更好
        4. Xianyancha
          1. 按-R-G-B-R-的順序,挑選已挑選數(shù)量非最大的顏色,保證偏R,偏G,偏B的顏色相對(duì)均勻。差值比例大于鮮艷差的認(rèn)為滿足鮮艷標(biāo)準(zhǔn)
          2. 經(jīng)過(guò)實(shí)踐鮮艷差設(shè)置為0.5-0.8效果更好
      2. 輸出內(nèi)容
        1. Gray_Index
          1. 根據(jù)輸入圖像構(gòu)建出的索引表
        2. MissingNumbers
          1. 完成篩選后,沒(méi)有對(duì)應(yīng)RGB組合的灰度值
          2. 篩選條件越苛刻Missing_Gray的數(shù)量越多
        3. junhendijige
          1. 最后被認(rèn)定為均衡并加入索引表的顏色在源顏色表的序號(hào)
          2. 這個(gè)序號(hào)越接近源顏色表的總長(zhǎng),認(rèn)為篩選條件設(shè)置越合理
        4. Xianyandijige
          1. 最后被認(rèn)定為鮮艷并加入索引表的顏色在源顏色表的序號(hào)
          2. 這個(gè)序號(hào)越接近顏色表的總長(zhǎng),認(rèn)為篩選條件設(shè)置的越合理
      3. 方法與流程
        1. 輸入?yún)?shù)規(guī)范化
          1. 格式轉(zhuǎn)換
        2. 構(gòu)建源顏色表
          1. 將RGB通道顏色聚合為128個(gè)等級(jí)值灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
          2. 統(tǒng)計(jì)顏色組合及其出現(xiàn)次數(shù)
          3. 統(tǒng)計(jì)chayis(單組rgb的最大值與最小值的差異)
          4. 構(gòu)建表最終結(jié)果按照差異降序,出現(xiàn)次數(shù)升序排序
        3. 根據(jù)輸入的判定參數(shù)遍歷順序遍歷整個(gè)源顏色表灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
        4. 缺失灰度值用距離最近的灰度代替灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
        5. 將最終索引表按照灰度值升序排序灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
    3. Byindexgetrgb
      1. 輸入內(nèi)容
        1. Gray_img
          1. 灰度圖像數(shù)據(jù)
        2. Index
          1. 顏色索引表
      2. 輸入內(nèi)容
        1. Rgb_img
          1. 根據(jù)灰度圖像與索引表恢復(fù)的RGB圖像
      3. 處理過(guò)程
        1. 輸入格式規(guī)范
        2. 遍歷圖像內(nèi)容,根據(jù)灰度值查找索引表對(duì)應(yīng)的RGB組合填充RGB
        3. 對(duì)填充后的RGB通道分別進(jìn)行中值濾波
    4. Gray_differup2rgb
      1. 輸入內(nèi)容
        1. GrayImg
          1. 灰度圖像(兼容彩色圖像)
        2. Mode
          1. 模式,1將高亮映射為暖色,0低亮映射為暖色
      2. 輸出內(nèi)容
        1. Result_rgbImg
          1. 處理結(jié)果
      3. 流程
        1. 參數(shù)規(guī)范
        2. 按模式分別對(duì)灰度值進(jìn)行函數(shù)映射
          1. 這里我們選用了線性的函數(shù)映射灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
    5. Miudfenge
      1. 輸入內(nèi)容
        1. Image
          1. 圖片信息,兼容彩色圖像
      2. 輸出內(nèi)容
        1. Colored_image
          1. 分割結(jié)果
      3. 過(guò)程
        1. 參數(shù)規(guī)范
        2. 計(jì)算每一段像素寬度
        3. 定義每一段色彩值灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
        4. 執(zhí)行密度分割灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
  • 三,GUI介紹

    1. 區(qū)域劃分
      1. 輸入?yún)^(qū)域灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
      2. 處理區(qū)域灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
      3. 輸出區(qū)域灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
    2. 效果展示
      1. 輸入?yún)^(qū)域
        1. 點(diǎn)擊上傳圖片或視頻灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab圖像會(huì)直接顯示,視頻會(huì)顯示第一幀
        2. 處理區(qū)域
          1. 列表選擇處理方法
            1. 灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
            2. 選擇后點(diǎn)擊處理
            3. 跳出彈窗指定參數(shù)灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab這里我們默認(rèn)了一組適用性比較廣泛的參數(shù)
            4. 點(diǎn)擊確定即可進(jìn)行處理
        3. 輸出區(qū)域
          1. 對(duì)于有結(jié)果需要展示的處理方法,會(huì)直接顯示原圖像與處理后的圖像
          2. 灰度偽彩色編碼,計(jì)算機(jī)視覺(jué),圖像處理,matlab
          3. 圖像與視頻均可處理
  • 四,源代碼

    1. byrgbgetindex
      1. function [gray_index,missingNumbers,junhendijige,xianyandijige,lenlong] = byrgbgetindex(rgb_img, bili ,junyuncha ,xianyancha)
        
        [~,~,k] = size(rgb_img);
        if k == 1
            rgb_img(:,:,1)=rgb_img(:,:,1);
            rgb_img(:,:,2)=rgb_img(:,:,2);
            rgb_img(:,:,3)=rgb_img(:,:,3);
        end
        
        if ischar(bili)
            bili = str2double(bili);
        end
        if ischar(junyuncha)
            junyuncha = str2double(junyuncha);
        end
        if ischar(xianyancha)
            xianyancha = str2double(xianyancha);
        end
        b = reshape(rgb_img, [], 3);
        
        % 獲取顏色組合和出現(xiàn)次數(shù)
        [colors, ~, index] = unique(b, 'rows');
        counts = accumarray(index, 1);
        
        % 計(jì)算灰度值
        grayValues = 0.2989 * colors(:, 1) + 0.5870*colors(:, 2) + 0.1140*colors(:, 3);
        
        %%   調(diào)整創(chuàng)建初始索引表,
        % 根據(jù)出現(xiàn)次數(shù)進(jìn)行排序
        [sortedCounts, idx] = sort(counts, 'descend');
        sortedColors = colors(idx, :);
        sortedGrayValues = grayValues(idx);
        
        
        % 由于單憑出現(xiàn)次數(shù)建立的索引表得到的圖像效果很差,所以為了使色彩更加鮮艷我以色彩差異(算是半個(gè)飽和度吧)為主建立了新的灰度預(yù)選表
        maxValues = max(sortedColors, [], 2);
        minValues = min(sortedColors, [], 2);
        chayis = maxValues-minValues; %計(jì)算差異大小
        [sortedfchayis, idxchayi] = sort(chayis, 'descend');
        chayisortedCounts = sortedCounts(idxchayi, :);
        chayisortedColors = sortedColors(idxchayi, :);
        chayisortedGrayValues = sortedGrayValues(idxchayi);
        newTable = table(sortedfchayis, chayisortedCounts, chayisortedColors(:, 1), chayisortedColors(:, 2), chayisortedColors(:, 3), chayisortedGrayValues, 'VariableNames', {'chayis', 'Counts', 'R', 'G', 'B', 'GrayValue'});
        newTable = sortrows(newTable, {'chayis', 'Counts'}, {'descend', 'descend'});
        
        
        % RGB聚合為128個(gè)等級(jí) 此時(shí)
        % 將RGB聚合(奇數(shù)減一,偶數(shù)不變)
        
        % 128分界線
        newTable.R = newTable.R - mod(newTable.R, 2);
        newTable.G = newTable.G - mod(newTable.G, 2);
        newTable.B = newTable.B - mod(newTable.B, 2);
        
        
        newTable.GrayValue = 0.2989 * newTable.R + 0.5870*newTable.G + 0.1140*newTable.B;
        
        
        
        %%  篩選最終索引表
        % 初始化結(jié)果列表和已選灰度值列表  
        selectedRGB = [];
        selectedGray = [];
        
        usedGrays = [];
        
        
        % 選擇灰度值
        % 優(yōu)化,均勻選擇,一半G均衡為主為主,剩下的一半,RGB鮮艷各占一份
        % 標(biāo)記 santi ={0,取均衡,1,取鮮艷}
        %      diqiu ={0,紅,1,綠,2藍(lán)}
        santi = 0;
        santinum = 0;
        junhendijige = 0;
        xianyandijige = 0;
        rnum = 0;
        gnum = 0;
        bnum = 0;
        lenlong = height(newTable);
        for i = 1:1:lenlong
            % 取出當(dāng)前 rgb 對(duì)應(yīng)的灰度值
            gray = newTable.GrayValue(i);
            
            % 檢查灰度是否已被選擇
            if ismember(gray, usedGrays)
                continue
            end
            
            if santi < bili
                if abs( newTable.G(i)-newTable.GrayValue(i)) <= junyuncha % 滿足條件的被選中
                    % 將灰度添加到已選列表中
                    usedGrays = [usedGrays; gray];
                    % 將 RGB 添加到結(jié)果列表中
                    selectedRGB = [selectedRGB; newTable.R(i), newTable.G(i), newTable.B(i)];
                    selectedGray = [selectedGray; gray];
                    santi = santi + 1; %santi 置1 下次選鮮艷
                    santinum = santinum + 1;
                    junhendijige = i;
                    continue;
                end
            end
            if santi == bili
                if newTable.R(i)/newTable.G(i) - 1 >= xianyancha && rnum-gnum <= 0 && rnum-bnum <= 0  %滿足條件被選中 
                    % 將灰度添加到已選列表中
                    usedGrays = [usedGrays; gray];
                    % 將 RGB 添加到結(jié)果列表中
                    selectedRGB = [selectedRGB; newTable.R(i), newTable.G(i), newTable.B(i)];
                    selectedGray = [selectedGray; gray];
                    santi = 0; %santi 置0 下次選均勻
                    rnum = rnum+1;
                    xianyandijige = i;
                    continue;
                elseif newTable.G(i)/newTable.B(i) - 1 >= xianyancha && gnum-bnum <= 0 && gnum-rnum <= 0  %滿足條件被選中
                    % 將灰度添加到已選列表中
                    usedGrays = [usedGrays; gray];
                    % 將 RGB 添加到結(jié)果列表中
                    selectedRGB = [selectedRGB; newTable.R(i), newTable.G(i), newTable.B(i)];
                    selectedGray = [selectedGray; gray];
                    santi = 0; %santi 置0 下次選均勻
                    gnum = gnum+1;
                    xianyandijige = i;
                    continue;
                elseif newTable.B(i)/newTable.R(i) - 1 >= xianyancha && bnum-rnum <= 0 && bnum-gnum <= 0  %滿足條件被選中
                    % 將灰度添加到已選列表中
                    usedGrays = [usedGrays; gray];
                    % 將 RGB 添加到結(jié)果列表中
                    selectedRGB = [selectedRGB; newTable.R(i), newTable.G(i), newTable.B(i)];
                    selectedGray = [selectedGray; gray];
                    santi = 0; %santi 置0 下次選均勻
                    bnum = bnum+1;
                    xianyandijige = i;
                    continue;
                end
            end
        
        
        end
        
        
        % 創(chuàng)建包含 0 到 255 的數(shù)組
        allNumbers = 0:255;
        
        % 找出 selectedRGB 中存在的數(shù)字
        presentNumbers = unique(selectedGray);
        
        % 找出缺失的數(shù)字
        missingNumbers = setdiff(allNumbers, presentNumbers);
        
        % 用距離最近的映射關(guān)系代替缺失的灰度值 
        for i = 1:length(missingNumbers)
            for j = 1:length(missingNumbers)*2
                
                if mod(j,2) == 0 
                    j = -j/2;
                else
                    j = (j+1)/2;
                end
                if missingNumbers(i)+j < 0
                    continue;
                end
                
                if ismember(missingNumbers(i)+j, selectedGray)
                    selectedGray = [selectedGray; missingNumbers(i)];
                    findout = find(selectedGray == missingNumbers(i)+j);
                    selectedRGB = [selectedRGB; selectedRGB(findout,:)];
                    break;
                end
            end
        end
        
        gray_index = table(selectedRGB(:, 1), selectedRGB(:, 2), selectedRGB(:, 3), selectedGray, 'VariableNames', {'R', 'G', 'B', 'Gray'});
        gray_index = sortrows(gray_index, 'Gray', 'ascend');
        
        
        end
        
        
        

        ????????

    2. byindexgetrgb
      1. function [rgb_img] = byindexgetrgb(gray_img, index)
        [row, col, k] = size(gray_img);
        rgb_img = zeros(row, col, 3, 'uint8');
        if k == 3
            gray_img = rgb2gray(gray_img);
        end
        array_table = table2array(index);
        gray_img_index = gray_img + 1;
        
        linear_index = sub2ind(size(array_table), gray_img_index(:));
        rgb_values = array_table(linear_index, :);
        
        rgb_img(:,:,1) = reshape(rgb_values(:, 1), row, col);
        rgb_img(:,:,2) = reshape(rgb_values(:, 2), row, col);
        rgb_img(:,:,3) = reshape(rgb_values(:, 3), row, col);
        rgb_img(:,:,1) = medfilt2(rgb_img(:,:,1), [3,3]);
        rgb_img(:,:,2) = medfilt2(rgb_img(:,:,2), [3,3]);
        rgb_img(:,:,3) = medfilt2(rgb_img(:,:,3), [3,3]);
        
        end
        

        ????????

    3. gray_differup2rgb
      1. %% 
        %   適用于醫(yī)學(xué)便于觀察——差異最大化的灰度圖像轉(zhuǎn)換
        %       關(guān)注低亮度區(qū)域時(shí):低亮度映射為紅色,高亮度映射為藍(lán)色;mode = 0
        %       關(guān)注高亮度區(qū)域時(shí):高亮度映射為紅色,低亮度映射為藍(lán)色;mode - 1
        %	分別用三個(gè)矩陣保存,三個(gè)通道的灰度值。每個(gè)通道的灰度值,有不同的映射函數(shù)。
        % 輸入灰度級(jí)        輸出彩色       
        % 0~50  1/5         藍(lán)色        紅色
        % 51~102 2/5        藍(lán)色+綠色   綠色+紅色
        % 103~153 3/5       綠色        綠色
        % 154~204  4/5      綠色+紅色   藍(lán)色+綠色
        % 205~255   5/5     紅色        藍(lán)色
        %% 
        % 
        % function [results_rgbImg] = gray_differup2rgb(grayImg,mode)
        % 
        % [row,col]=size(grayImg);
        % R = zeros(row,col);
        % G = zeros(row,col);
        % B = zeros(row,col);
        % 
        % 
        % if mode == 1
        %     for i = 1:row
        %         for j = 1:col
        %             if grayImg(i,j)<=50 % [0,50]
        %                 R(i,j)=0;
        %                 G(i,j)=0;
        %                 B(i,j)=255;
        %                 
        %             elseif grayImg(i,j)<=102 % (51,102] 
        %                 R(i,j)=0;
        %                 G(i,j)=5*(grayImg(i,j)-50);
        %                 B(i,j)=255-5*(grayImg(i,j)-50);
        %             elseif grayImg(i,j)<=153% (103, 153]
        %                 R(i,j)=0;
        %                 G(i,j)=255;
        %                 B(i,j)=0;
        %              
        %             elseif grayImg(i,j)<=204% (154, 204]
        %                 R(i,j)=5*(grayImg(i,j)-153);
        %                 G(i,j)=255-5*(grayImg(i,j)-153);
        %                 B(i,j)=0;
        %          
        %             else              % (205,255]
        %                 R(i,j)=255;
        %                 G(i,j)=0;
        %                 B(i,j)=0;
        %             end
        %         end
        %     end
        %     
        %     results_rgbImg = zeros(row,col);
        %     for i=1:row
        %         for j=1:col
        %               results_rgbImg(i,j,1)=R(i,j);
        %               results_rgbImg(i,j,2)=G(i,j);
        %               results_rgbImg(i,j,3)=B(i,j);
        %         end
        %     end
        %  
        %     results_rgbImg=results_rgbImg/256;
        % elseif mode == 0
        %     for i = 1:row
        %         for j = 1:col
        %             if grayImg(i,j)<=50 % [0,50]
        %                 
        %                 R(i,j)=255;
        %                 G(i,j)=0;
        %                 B(i,j)=0;
        %             elseif grayImg(i,j)<=102 % (51,102] 
        %                 
        %                 R(i,j)=5*(grayImg(i,j)-153);
        %                 G(i,j)=255-5*(grayImg(i,j)-153);
        %                 B(i,j)=0;
        %             elseif grayImg(i,j)<=153% (103, 153]
        %                 R(i,j)=0;
        %                 G(i,j)=255;
        %                 B(i,j)=0;
        %             elseif grayImg(i,j)<=204% (154, 204]
        %                 R(i,j)=0;
        %                 G(i,j)=5*(grayImg(i,j)-50);
        %                 B(i,j)=255-5*(grayImg(i,j)-50);
        % 
        %             else              % (205,255]
        %                 R(i,j)=0;
        %                 G(i,j)=0;
        %                 B(i,j)=255;
        %             end
        %         end
        %     end
        %     
        %     results_rgbImg = zeros(row,col);
        %     for i=1:row
        %         for j=1:col
        %               results_rgbImg(i,j,1)=R(i,j);
        %               results_rgbImg(i,j,2)=G(i,j);
        %               results_rgbImg(i,j,3)=B(i,j);
        %         end
        %     end
        %  
        %     results_rgbImg=results_rgbImg/256;
        %     
        % end
        % end
        %%    改進(jìn)版本,速度有所提升
        function results_rgbImg = gray_differup2rgb(grayImg, mode)
        if ischar(mode)
            mode = str2double(mode);
        end
        [row, col, k] = size(grayImg);
        R = zeros(row, col);
        G = zeros(row, col);
        B = zeros(row, col);
        
        % 檢查輸入圖像是否為灰度圖像
        if k == 3
            grayImg = rgb2gray(grayImg);
        end
        
        
        
        if mode == 1
            % [0,50]
            idx = grayImg <= 50;
            R(idx) = 0;
            G(idx) = 0;
            B(idx) = 255;
            
            % (51,102]
            idx = (grayImg > 50) & (grayImg <= 102);
            G(idx) = 5 * (grayImg(idx) - 50);
            B(idx) = 255 - 5 * (grayImg(idx) - 50);
            
            % (103, 153]
            idx = (grayImg > 102) & (grayImg <= 153);
            G(idx) = 255;
            B(idx) = 0;
            
            % (154, 204]
            idx = (grayImg > 153) & (grayImg <= 204);
            R(idx) = 5 * (grayImg(idx) - 153);
            G(idx) = 255 - 5 * (grayImg(idx) - 153);
            
            % (205,255]
            idx = grayImg > 204;
            R(idx) = 255;
            G(idx) = 0;
            B(idx) = 0;
            
        elseif mode == 0
            % [0,50]
            idx = grayImg <= 50;
            R(idx) = 255;
            G(idx) = 0;
            B(idx) = 0;
            
            % (51,102]
            idx = (grayImg > 50) & (grayImg <= 102);
            R(idx) = 5 * (grayImg(idx) - 153);
            G(idx) = 255 - 5 * (grayImg(idx) - 153);
            
            % (103, 153]
            idx = (grayImg > 102) & (grayImg <= 153);
            G(idx) = 255;
            B(idx) = 0;
            
            % (154, 204]
            idx = (grayImg > 153) & (grayImg <= 204);
            G(idx) = 5 * (grayImg(idx) - 50);
            B(idx) = 255 - 5 * (grayImg(idx) - 50);
            
            % (205,255]
            idx = grayImg > 204;
            R(idx) = 0;
            G(idx) = 0;
            B(idx) = 255;
        end
        
        results_rgbImg = cat(3, R, G, B)/255;
        
        end
        

        ????????

    4. midufenge
      1. 
        function [colored_image] = midufenge(image)
        %PINLUCHENGFEN 輸入灰度圖,選擇成分:傅里葉變換濾除目標(biāo)成分
        
        [~,~,k] = size(image);
        if k == 3
            image = rgb2gray(image);
        end
        
        
        gray_image_double = double(image)/255;
        [row, col] = size(gray_image_double);
        
        % 定義分割段數(shù)
        N = 5;
        % 計(jì)算灰度值的最大值和最小值
        max_value = max(max(gray_image_double));
        min_value = min(min(gray_image_double));
        % 計(jì)算每一段的像素值域?qū)挾?step = (max_value - min_value) / N;
        % 定義每一段的彩色值
        colors = [0 0 1; 0 1 1; 0 1 0; 1 1 0; 1 0 0]; % 藍(lán)->青->綠->黃->紅
        
        % 執(zhí)行密度分割法
        colored_image = zeros(row, col, 3);
        for i = 1:N
            start_gray = min_value + (i - 1) * step;
            end_gray = min_value + i * step;
            
            % 找到屬于當(dāng)前段的像素值
            mask = (gray_image_double >= start_gray) & (gray_image_double < end_gray);
            
            
            % 將彩色圖像賦值給對(duì)應(yīng)的像素
            for j = 1:row
                for k = 1:col
                    if mask(j,k) == 1
                        colored_image(j,k,1) = colors(i,1);
                        colored_image(j,k,2) = colors(i,2);
                        colored_image(j,k,3) = colors(i,3);
                    end
                end
            end
            
        end
        
        end
        

        ????????文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-827451.html

    5. last
      1. myGUIApp();
        
        function myGUIApp()
            % 創(chuàng)建主窗口
            mainFig = figure('Name', 'My GUI App', 'Position', [200,200,800,600]);
            %%
            % 定義handles結(jié)構(gòu)體,用于不同回調(diào)函數(shù)之間的變量共享
            handles = struct();
            handles.inputimg = []; % 輸入圖片
            handles.inputvid = []; % 輸入視頻
            handles.outimg = []; % 處理結(jié)果圖片
            handles.outvid = []; % 處理結(jié)果視頻
            handles.pathname = [];
            handles.outindex = [];
            handles.missingNumbers = [];
            handles.junhendijige = [];
            handles.xianyandijige = [];
            handles.lenlong = [];
            %%
            % 創(chuàng)建輸入?yún)^(qū)域
            inputPanel = uipanel('Parent', mainFig, 'Title', '待處理圖像或視頻', 'Position', [0.05, 0.6, 0.4, 0.35]);
            imageAxes = axes('Parent', inputPanel, 'Position', [0.05, 0.15, 0.9, 0.8]);
            loadImageButton = uicontrol('Parent', inputPanel, 'Style', 'pushbutton', 'String', '讀取圖像', 'Position', [20, 20, 100, 30], 'Callback', @loadImageCallback);
            loadVideoButton = uicontrol('Parent', inputPanel, 'Style', 'pushbutton', 'String', '讀取視頻', 'Position', [140, 20, 100, 30], 'Callback', @loadVideoCallback);
            
            % 創(chuàng)建處理區(qū)域
            processPanel = uipanel('Parent', mainFig, 'Title', '處理方法選擇', 'Position', [0.55, 0.6, 0.4, 0.35]);
            methodPopup = uicontrol('Parent', processPanel, 'Style', 'popupmenu', 'String', {'生成索引表', '通過(guò)索引表構(gòu)建RGB圖像', '亮度冷暖圖','密度分割法'}, 'Position', [20, 20, 150, 30]);
            processButton = uicontrol('Parent', processPanel, 'Style', 'pushbutton', 'String', '處理', 'Position', [180, 20, 100, 30], 'Callback', @processImageCallback);
        
            % 創(chuàng)建輸出區(qū)域
            outputPanel = uipanel('Parent', mainFig, 'Title', '結(jié)果展示', 'Position', [0.05, 0.1, 0.9, 0.45]);
            resultAxes = axes('Parent', outputPanel, 'Position', [0.05, 0.15, 0.4, 0.7]);
            resultAxes1 = axes('Parent', outputPanel, 'Position', [0.55, 0.15, 0.4, 0.7]);
            infoEdit = uicontrol('Parent', outputPanel, 'Style', 'edit', 'Max', 2, 'HorizontalAlignment', 'left', 'Position', [0.5, 0.15, 0.45, 0.7]);
            %%
            % 圖像讀取回調(diào)函數(shù)
            function loadImageCallback(~, ~)
                % 獲取當(dāng)前的handles結(jié)構(gòu)體
                handles = guidata(gcf);
        
                % 打開(kāi)文件選擇對(duì)話框
                [FileName,handles.pathname] = uigetfile({'*.jpg;*.jpeg;*.png;*.bmp','Image files (*.jpg, *.jpeg, *.png, *.bmp)'},'選擇一張圖像');
        
                % 如果用戶取消選擇圖像,則返回
                if isequal(FileName,0)
                    return;
                end
        
                % 讀取圖像并在axes中顯示
                handles.inputimg = imread(fullfile(handles.pathname, FileName));
            
                % 將讀取到的變量存儲(chǔ)到handles結(jié)構(gòu)體中
                
                handles.inputvid = [];
            
                imshow(handles.inputimg, 'Parent', imageAxes);
        
                % 存儲(chǔ)更新后的handles結(jié)構(gòu)體
                guidata(gcf, handles);
            end
            %%
            % 視頻讀取回調(diào)函數(shù)
            function loadVideoCallback(~, ~)
                % 獲取當(dāng)前的handles結(jié)構(gòu)體
                handles = guidata(gcf);
                
                % 打開(kāi)文件選擇對(duì)話框
                [FileName,handles.pathname] = uigetfile({'*.avi;*.mp4;*.mov','Video files (*.avi, *.mp4, *.mov)'},'選擇一個(gè)視頻');
            
                % 如果用戶取消選擇視頻,則返回
                if isequal(FileName,0)
                    return;
                end
            
                % 讀取視頻并存儲(chǔ)為一個(gè)VideoReader對(duì)象
                handles.inputvid = VideoReader(fullfile(handles.pathname, FileName));
                handles.outvid = VideoWriter(fullfile(handles.pathname, 'output.avi')); % 創(chuàng)建用于保存處理后幀的新視頻
                
                % 將讀取到的變量存儲(chǔ)到handles結(jié)構(gòu)體中
                handles.inputimg = [];
                % 在axes中顯示第一幀圖像
                frame = read(handles.inputvid, 1);
                imshow(frame, 'Parent', imageAxes);
                
                % 存儲(chǔ)更新后的handles結(jié)構(gòu)體
                guidata(gcf, handles);
            end
        
            %%
            function processImageCallback(~, ~)
                % 獲取當(dāng)前的handles結(jié)構(gòu)體
                handles = guidata(gcf);
                
                % 獲取選擇的處理方法
                methodIndex = get(methodPopup, 'Value');
                methodList = {'生成索引表', '通過(guò)索引表構(gòu)建RGB圖像', '亮度冷暖圖','密度分割法'};
                selectedMethod = methodList{methodIndex};
                %%
                if size(handles.inputvid) == 0
                    % 根據(jù)選擇的方法調(diào)用相應(yīng)的處理函數(shù)
                    if strcmp(selectedMethod, '生成索引表')
                        handles.outindex = [];
                        handles.missingNumbers = [];
                        handles.junhendijige = [];
                        handles.xianyandijige = [];
                        handles.lenlong = [];
                        % 彈出對(duì)話框獲取方法1的參數(shù)值
                        prompt = {'非飽和占比:', '非飽和指標(biāo):', '飽和指標(biāo):'};
                        dlgtitle = '輸入?yún)?shù)';
                        dims = [1 35];
                        definput = {'15', '2','0.5'};
                        params = inputdlg(prompt, dlgtitle, dims, definput);
        
                        % 調(diào)用方法1的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        [handles.outindex,handles.missingNumbers,handles.junhendijige,handles.xianyandijige,handles.lenlong] = byrgbgetindex(handles.inputimg, params{:});
                    elseif strcmp(selectedMethod, '通過(guò)索引表構(gòu)建RGB圖像')
                        % 調(diào)用方法2的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        handles.outimg = []; % 處理結(jié)果圖片
                        handles.outimg = byindexgetrgb(handles.inputimg, handles.outindex);
                    
                        % 在結(jié)果區(qū)域顯示處理結(jié)果
                        [~,~,k] = size(handles.inputimg);
                        if k == 3 
                            gray_img = rgb2gray(handles.inputimg);
                        else
                            gray_img = handles.inputimg;
                        end
                        
                        imshow(gray_img, 'Parent', resultAxes);
                        imshow(handles.outimg, 'Parent', resultAxes1);
                    elseif strcmp(selectedMethod, '亮度冷暖圖')
                        handles.outimg = []; % 處理結(jié)果圖片
                        % 彈出對(duì)話框獲取方法3的參數(shù)值
                        
                        prompt = {'關(guān)注成分選擇:'};
                        dlgtitle = '輸入?yún)?shù)';
                        dims = [1 35];
                        definput = {'1'};
                        params = inputdlg(prompt, dlgtitle, dims, definput);
        
                        % 調(diào)用方法3的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        handles.outimg = gray_differup2rgb(handles.inputimg , params{:});
                        % 在結(jié)果區(qū)域顯示處理結(jié)果
                        [~,~,k] = size(handles.inputimg);
                        if k == 3 
                            gray_img = rgb2gray(handles.inputimg);
                        else
                            gray_img = handles.inputimg;
                        end
                        imshow(gray_img, 'Parent', resultAxes);
                
                        imshow(handles.outimg, 'Parent', resultAxes1);
             
                    elseif strcmp(selectedMethod, '密度分割法')
                        handles.outimg = []; % 處理結(jié)果圖片
                        
        
                        % 調(diào)用方法4的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        handles.outimg = midufenge(handles.inputimg);
                        % 在結(jié)果區(qū)域顯示處理結(jié)果
                        [~,~,k] = size(handles.inputimg);
                        if k == 3 
                            gray_img = rgb2gray(handles.inputimg);
                        else
                            gray_img = handles.inputimg;
                        end
                        imshow(gray_img, 'Parent', resultAxes);
                        imshow(handles.outimg, 'Parent', resultAxes1);
                    end
                end
                %%
                if size(handles.inputimg) == 0
                    % 根據(jù)選擇的方法調(diào)用相應(yīng)的處理函數(shù)
                    if strcmp(selectedMethod, '生成索引表')
                        handles.outindex = [];
                        handles.missingNumbers = [];
                        handles.junhendijige = [];
                        handles.xianyandijige = [];
                        handles.lenlong = [];
                        % 彈出對(duì)話框獲取方法1的參數(shù)值
                        prompt = {'非飽和占比:', '非飽和指標(biāo):', '飽和指標(biāo):'};
                        dlgtitle = '輸入?yún)?shù)';
                        dims = [1 35];
                        definput = {'15', '2','0.5'};
                        params = inputdlg(prompt, dlgtitle, dims, definput);
        
                        % 調(diào)用方法1的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        frameSequence = cell(1, 5);
                        if handles.inputvid.NumFrames < 5
                            concatenatedImage = readFrame(handles.inputvid);
                        else
                            for i = 1:5
                                frame = readFrame(handles.inputvid);
                                frameSequence{i} = frame;
                            end
                            concatenatedImage = cat(2, frameSequence{:});
                        end
                        
                        [handles.outindex,handles.missingNumbers,handles.junhendijige,handles.xianyandijige,handles.lenlong] = byrgbgetindex(concatenatedImage, params{:});
                    elseif strcmp(selectedMethod, '通過(guò)索引表構(gòu)建RGB圖像')
                        % 調(diào)用方法2的處理函數(shù),并傳遞用戶輸入的參數(shù)值
        
                        
                        open(handles.outvid); % 打開(kāi)新視頻文件
                        while hasFrame(handles.inputvid)
                            frame = readFrame(handles.inputvid);
                            [~,~,k] = size(frame);
                            % 對(duì)當(dāng)前幀進(jìn)行處理
                            if k == 3 
                                frame = rgb2gray(frame);
                            end
                            imshow(frame, 'Parent', resultAxes);
                            frame = byindexgetrgb(frame, handles.outindex);
                            imshow(frame, 'Parent', resultAxes1);
                            % 將處理后的幀寫入新視頻
                            writeVideo(handles.outvid, frame);
                            pause(0.0333); % 控制幀率為30fps
                                
                        end
                        close(handles.outvid); % 關(guān)閉新視頻文件
                    
                    elseif strcmp(selectedMethod, '亮度冷暖圖')
                        % 彈出對(duì)話框獲取方法3的參數(shù)值
                        prompt = {'關(guān)注成分選擇:'};
                        dlgtitle = '輸入?yún)?shù)';
                        dims = [1 35];
                        definput = {'1'};
                        params = inputdlg(prompt, dlgtitle, dims, definput);
        
                        % 調(diào)用方法3的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        open(handles.outvid); % 打開(kāi)新視頻文件
                        while hasFrame(handles.inputvid)
                            frame = readFrame(handles.inputvid);
                            [~,~,k] = size(frame);
                            % 對(duì)當(dāng)前幀進(jìn)行處理
                            if k == 3 
                                frame = rgb2gray(frame);
                            end
                            imshow(frame, 'Parent', resultAxes);
                            frame = gray_differup2rgb(frame , params{:});
                            imshow(frame, 'Parent', resultAxes1);
                            % 將處理后的幀寫入新視頻
                            writeVideo(handles.outvid, frame);
                            pause(0.0333); % 控制幀率為30fps
                                
                        end
                        close(handles.outvid); % 關(guān)閉新視頻文件
             
                    elseif strcmp(selectedMethod, '密度分割法')
                        
        
                        % 調(diào)用方法4的處理函數(shù),并傳遞用戶輸入的參數(shù)值
                        open(handles.outvid); % 打開(kāi)新視頻文件
                        while hasFrame(handles.inputvid)
                            frame = readFrame(handles.inputvid);
                            [~,~,k] = size(frame);
                            % 對(duì)當(dāng)前幀進(jìn)行處理
                            if k == 3 
                                frame = rgb2gray(frame);
                            end
                            imshow(frame, 'Parent', resultAxes);
                            frame = midufenge(frame);
                            imshow(frame, 'Parent', resultAxes1);
                            % 將處理后的幀寫入新視頻
                            writeVideo(handles.outvid, frame);
                            pause(0.0333); % 控制幀率為30fps
                                
                        end
                        close(handles.outvid); % 關(guān)閉新視頻文件
                    end
                end
        
                % 將handles變量存儲(chǔ)到主窗口中
                guidata(gcf, handles);
            end
        end

到了這里,關(guān)于數(shù)字圖像處理——灰度圖像(視頻)轉(zhuǎn)化偽彩色圖像(視頻)(含源代碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 彩色圖像處理之彩色圖像直方圖處理的python實(shí)現(xiàn)——數(shù)字圖像處理

    彩色圖像處理之彩色圖像直方圖處理的python實(shí)現(xiàn)——數(shù)字圖像處理

    彩色圖像的直方圖處理是一種重要的圖像處理技術(shù),用于改善圖像的視覺(jué)效果,增強(qiáng)圖像的對(duì)比度,或?yàn)楹罄m(xù)的圖像處理任務(wù)(如圖像分割、特征提?。┳鰷?zhǔn)備。彩色圖像通常由紅色(R)、綠色(G)、藍(lán)色(B)三個(gè)顏色通道組成,因此彩色圖像的直方圖處理相比單色圖像更

    2024年01月23日
    瀏覽(25)
  • 數(shù)字圖像處理第六章——彩色圖像處理

    數(shù)字圖像處理第六章——彩色圖像處理

    目錄 引言 一、彩色基礎(chǔ) 二、彩色模型 2.1 RGB彩色模型 2.2 CMY和CMYK彩色模型 ?2.3 HSI彩色模型 三、偽彩色圖像處理 3.1 灰度分層 3.2 灰度到彩色的變換 四、彩色變換 ?編輯色調(diào)與色彩校正 五、平滑與銳化 5.1 平滑 5.2 銳化 ????????在圖像處理中,彩色的運(yùn)用受兩個(gè)主要因素

    2024年02月09日
    瀏覽(98)
  • 基于matlab的數(shù)字圖像處理之彩色圖像處理

    基于matlab的數(shù)字圖像處理之彩色圖像處理

    一、實(shí)驗(yàn)?zāi)康?(1)了解如何利用RGB分量生成簡(jiǎn)單的圖像。 (2)熟練掌握RGB彩色模型轉(zhuǎn)換到HIS彩色模型的過(guò)程。 (3)熟練掌握RGB圖像的彩色分割。 (4)熟練掌握彩色圖像如何在向量空間中進(jìn)行邊緣檢測(cè)。 二、實(shí)驗(yàn)儀器(軟件平臺(tái)) ??? 計(jì)算機(jī)、MATLAB軟件 三、實(shí)驗(yàn)原理

    2024年02月06日
    瀏覽(24)
  • matlab數(shù)字圖像處理——圖像的讀寫,灰度、二值圖像

    matlab數(shù)字圖像處理——圖像的讀寫,灰度、二值圖像

    一、實(shí)驗(yàn)?zāi)康?1.結(jié)合數(shù)字圖像處理的知識(shí),直觀感受圖像處理的基本實(shí)現(xiàn)過(guò)程 2.熟悉MATLAB工具的使用 3.了解圖像的讀寫和顯示 二、實(shí)驗(yàn)內(nèi)容 實(shí)驗(yàn)內(nèi)容一:圖像讀取 (1)利用編程實(shí)現(xiàn)讀取圖像 利用imread讀取文件夾images中的圖像;查看讀取到的圖像數(shù)據(jù)矩陣,對(duì)比灰度圖像、

    2024年02月07日
    瀏覽(22)
  • (數(shù)字圖像處理MATLAB+Python)第五章圖像增強(qiáng)-第四、五節(jié):基于模糊技術(shù)和基于偽彩色處理的圖像增強(qiáng)

    (數(shù)字圖像處理MATLAB+Python)第五章圖像增強(qiáng)-第四、五節(jié):基于模糊技術(shù)和基于偽彩色處理的圖像增強(qiáng)

    圖像的模糊特征平面 :假設(shè)原始圖像為 I ( x , y ) I(x,y) I ( x , y ) ,其中 x x x 和 y y y 分別表示圖像的水平和垂直方向的坐標(biāo)。模糊特征平面可以表示為 B ( x , y , θ ) B(x,y,theta) B ( x , y , θ ) ,其中 θ theta θ 是一個(gè)旋轉(zhuǎn)角度參數(shù),表示模糊核函數(shù)的旋轉(zhuǎn)角度。 B ( x , y , θ ) B(x,

    2023年04月20日
    瀏覽(101)
  • Matlab對(duì)圖像和視頻的簡(jiǎn)單處理(圖像視頻文件讀取和輸出,轉(zhuǎn)灰度圖,取指定幀的圖像)

    語(yǔ)法介紹 : 參數(shù)介紹 : filename :要讀取的圖像文件名,可以是完整的路徑。 fmt :可選參數(shù),指定圖像的格式。默認(rèn)情況下,imread會(huì)嘗試猜測(cè)文件格式。常用的格式包括 ‘bmp’、‘gif’、‘jpeg’、‘png’、\\\'tiff’等。 返回值 : A :返回讀取的圖像數(shù)據(jù)矩陣,它可以是灰度

    2024年02月06日
    瀏覽(91)
  • 【數(shù)字圖像處理】灰度圖像中添加高斯噪聲、椒鹽噪聲、斑點(diǎn)噪聲以及利用不同方法(中值、排序、維納濾波)去除各種噪聲的matlab程序

    【數(shù)字圖像處理】灰度圖像中添加高斯噪聲、椒鹽噪聲、斑點(diǎn)噪聲以及利用不同方法(中值、排序、維納濾波)去除各種噪聲的matlab程序

    圖像處理問(wèn)題描述: 1、圖像中分別加入不同方差的高斯噪聲、不同噪聲密度椒鹽噪聲和不同方差的斑點(diǎn)噪聲(Gaussian noise, salt ?pepper noise and speckle noise) 2、分別通過(guò)函數(shù)medfilt2、ordfilt2和?Wiener 2 去除圖像中添加的一些噪聲(Gaussian noise, salt ?pepper noise and speckle noise)。 各部

    2024年02月07日
    瀏覽(30)
  • 嵌入式教學(xué)實(shí)驗(yàn)箱_數(shù)字信號(hào)處理實(shí)驗(yàn)箱_操作教程:5-16 灰度圖像線性變換(LCD顯示)

    嵌入式教學(xué)實(shí)驗(yàn)箱_數(shù)字信號(hào)處理實(shí)驗(yàn)箱_操作教程:5-16 灰度圖像線性變換(LCD顯示)

    學(xué)習(xí)灰度圖像線性變換的原理,掌握?qǐng)D像的讀取方法,并實(shí)現(xiàn)在LCD上顯示線性變換前后的圖像。 一般成像系統(tǒng)只具有一定的亮度范圍,亮度的最大值與最小值之比稱為對(duì)比度。由于形成圖像的系統(tǒng)亮度有限,常出現(xiàn)對(duì)比度不足的弊病,使人眼觀看圖像時(shí)視覺(jué)效果很差,通過(guò)灰

    2024年02月03日
    瀏覽(96)
  • 偽彩色圖像處理

    偽彩色圖像處理

    ? ??偽彩色處理(pseudocoloring)是指根據(jù)一定準(zhǔn)則給灰度值賦予彩色值的處理。宏觀來(lái)說(shuō)就是將黑白圖像轉(zhuǎn)化為彩色圖像,或者是將單色圖像變換成給定彩色分布的圖像。由于人眼對(duì)彩色的分辨能力遠(yuǎn)遠(yuǎn)高于對(duì)灰度的分辨能力,所以將灰度圖像轉(zhuǎn)化成彩色表示,就可以提高對(duì)圖

    2024年02月13日
    瀏覽(29)
  • 圖像處理之圖像灰度化

    圖像處理之圖像灰度化

    圖像灰度化 彩色圖像中的每個(gè)像素的顏色有R、G、B三個(gè)分量決定,而每個(gè)分量有255中值可取,這樣一個(gè)像素點(diǎn)可以有1600多萬(wàn) (255 255 255)的顏色的變化范用。而灰度圖像是R、G、B三個(gè)分量相同的一種特殊的彩色圖像(R=G=B),其一個(gè)像素點(diǎn)的變化范圍為255種,所以在數(shù)字圖像處理

    2024年02月15日
    瀏覽(25)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包