How can i Change pixel color?

조회 수: 89 (최근 30일)
Ansam Nazar
Ansam Nazar 2020년 7월 7일
댓글: Image Analyst 2020년 7월 12일
Hello
I have a color image of type RGB and I need to change the color of each point (red, yellow, orange) to green. I hope that there is a programmatic solution to this problem.
  댓글 수: 5
jonas
jonas 2020년 7월 7일
Better replace loop by logical indexing and upload an example image.
Mehmed Saad
Mehmed Saad 2020년 7월 8일
jonas is right, understand the code and try to replace for loops with logical indexing

댓글을 달려면 로그인하십시오.

채택된 답변

Mehmed Saad
Mehmed Saad 2020년 7월 7일
편집: Mehmed Saad 2020년 7월 8일
I = imread('red.jpg');
figure,subplot(121),imshow(I)
th = 20;
[x,y,~]=size(I);
for ii=1:x
for jj=1:y
if((I(ii,jj,1)-th)> I(ii,jj,2)&& (I(ii,jj,1)-th)>I(ii,jj,3))
I(ii,jj,1) = 0;I(ii,jj,2) = 255;I(ii,jj,3) = 0;
end
end
end
subplot(122),imshow(I)
For same effect you can try this
I(ii,jj,1:2) = circshift(I(ii,jj,1:2),1);
I(:,:,1:2) = circshift(I(:,:,1:2),1,3);%without for loop
  댓글 수: 4
Ansam Nazar
Ansam Nazar 2020년 7월 12일
Thanks alot for all of your help. but the function is not working in Matlab R2018a. the error was:
"Undefined function or variable 'imsplit'."
Image Analyst
Image Analyst 2020년 7월 12일
You can do it manually:
r = rgbImage(:, :, 1);
g = rgbImage(:, :, 2);
b = rgbImage(:, :, 3);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by