2014-10-28 4 views
-1

일부 픽셀 색상 (벡터 row_first에있는 픽셀)이 녹색으로 바뀌지 만 이미지가이 픽셀 값을 변경하지만 모든 이미지가 빨간색이면 원본 이미지 img_cropdouble rgb입니다. .픽셀 단위의 색상이 MATLAB에서 변경됨

내 코드는 다음과 같습니다 :

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 나는 녹색으로 TOC의 hange을 원하는 image_crop의 픽셀에 대한 열마다, 첫 번째 줄에 rowsindex을 가진 벡터이다.

기본적으로 가장 큰 행 값을 가진 첫 번째 최대 값을 찾고이 다음에 최소값을 찾고 싶습니다. 그런 다음 내 조건 (중요하지 않음)에 해당하는 최소값을 찾은 다음 이것은 내가

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); 

것은 내가 원본 이미지 (왼쪽)이 첨부 아래와 같이 쓴 코드, 그리고 (오른쪽) 최종


012 첫 번째 최소 픽셀 enter image description here

페인트

왜 이런 일이 발생합니까? 오류는 무엇입니까?

+2

각 열의 '1'픽셀을 변경하는 중입니다. 원하는 것이 맞습니까? – Rashid

+0

목표는 무엇입니까? 'row_first'에 대한 예제를 제공합니다. – Rashid

+0

픽셀을 어떻게 변경하는지 잘 모르겠습니다. 첫 번째 차원 (행)에 액세스하는 데'row_first '를 사용하고 있지만 두 번째 차원 (열)은 루프 인덱스'j'를 사용하여 변합니다. 이게 니가 원하는거야? 또한, 어떻게'img_crop'이 선언되고 있습니까? 이미지를 설정하고'for' 루프로 안내하는 더 많은 코드를 보여주십시오. 게시물을 수정하고 대신 실제로 픽셀 값을 수정하는 방법을 설명하십시오. – rayryeng

답변

0

img_crop을 정의하는 중입니다. 그럼에도 불구하고 코드를 살펴보면 RGB 이미지를 선언하고 있지만 처음에는 채널img_gauss으로 설정하고 있습니다. img_crop을 이렇게 선언하고 코드를 다시 시험해보십시오.

img_crop = cat(3,img_gauss,img_gauss,img_gauss); 
관련 문제