在MATLAB中,像素方式的颜色发生了变化

时间:2014-10-28 21:41:17

标签: matlab colors pixel

我将一些像素颜色(矢量row_first中的像素)更改为绿色,但图像会更改此像素值,但所有图像都是红色,我的原始图像img_cropdouble rgb

我的代码如下:

 for j=1:size(img_crop,2)%column
       img_crop(row_first(1,j),j,1)=0;
       img_crop(row_first(1,j),j,2)=1;
       img_crop(row_first(1,j),j,3)=0;
 end

Row_first是一个向量,在第一行中有rowsindex,每列用于image_crop中的像素,我希望将其变为绿色。

基本上我想找到第一个最大值(具有最高行值,然后我想在此之前找到下一个最小值),然后找到与我的条件对应的最小值(不重要),然后绘制第一个最小像素enter image description here

这是我在下面写的代码

for x = 1:size(img_gauss,2) 

%   for y=1:size(img_gauss,1)
    % Make a row wise intensity distribution graphic for each column starting
    %from the first row to the last because findpeaks will  assigned the
    %indices in that order, and then select the last
    %max will correspond to the far adventtitia

    %Find the peaks,local maximum for each column and assignment to the
    %respective column

    [z,local_min] = findpeaks(-img_gauss(1:size(img_gauss,1),x));%local min
    % Verify if this local minimum pixels are possible candidates for
    % lumen:
    for w=1:size(local_min,1)%rows
        if (mean_pixel(local_min(w,1),x)<0.0004705 && std_pixel(local_min(w,1),x)<0.0017)
            lumen_local(w,x)=local_min(w,1); 

        else
            nao_lumen(w,x)=local_min(w,1);
        end
    end

    % coordinates of the local maximum values
    [g,local_max]=findpeaks(img_gauss(1:size(img_gauss,1),x));%local max

    local_max(:,x)=local_max(:,1);

    % Assignm each maximum and minimum position  to the respective column,
    %per iteration, and sort both in a descendent way
    max_column(1:size(local_max,1),x)=sort(local_max(1:size(local_max,1),x),'descend');
    min_column(1:size(lumen_local,1),x)=sort(lumen_local(1:size(lumen_local,1),x),'descend');


% BW = imregionalmin(img_gauss(y,x)); 

  end
% end

for q=1:size(img_gauss,2)
    for a=1:size(img_gauss,1)
        if mean_pixel(a,q)<0.0004705 && std_pixel(a,q)<0.0017 
            img_gauss(a,q)=1;%white
        else 
            img_gauss(a,q)=0;%black
        end
    end
end      
figure(9), imshow(img_gauss);
img_close=imclose(img_gauss,ones(20,20));
figure(10),imshow(img_close);

  % The first maximum with the highest row number correspond to the
  % adventícia,so now the first minimum  before correspond to the lumen

  for i=1:size(max_column,2)
      max_adve(:,i)=max_column(1,i);% [row col] of the the first adventicia pixel
      row_first(1,i)= min_column(find(min_column(:,i)<max_adve(:,i),1),i);
  end

   % Put the lumen pixels at green
   for j=1:size(img_crop,2)%column
       img_crop(row_first(1,j),j,1)=0;%R
       img_crop(row_first(1,j),j,2)=1;%G
       img_crop(row_first(1,j),j,3)=0;%B
   end

 figure(11),imshow(img_crop);

附上我有原始图像(左)和最终图像(右)


为什么会发生这种情况,错误是什么?

1 个答案:

答案 0 :(得分:0)

您还没有告诉我们 您定义的img_crop。不过,通过查看您的代码,我的猜测是您要声明RGB图像,但您只是将第一个频道设置为img_gauss。以这种方式声明img_crop并再次尝试您的代码:

img_crop = cat(3,img_gauss,img_gauss,img_gauss);
相关问题