필터 지우기
필터 지우기

I have written the code to convert the RGB to different color ,in the command window result is correct but the resulting image was not displayed

조회 수: 1 (최근 30일)
clc
close all;
clear all;
[fname path]=uigetfile('*.*','insert the pic');
a=imread(fname);
imshow(a)
w=0;d=0;z=0;
b=zeros(size(a,1),size(a,2),size(a,3));
for i=1:size(a,1)
for j=1:size(a,2)
for k=1:size(a,3)
if a(i,j,k)<=80
b(i,j,k)=34;
w=w+1;
elseif a(i,j,k)<=120
b(i,j,k)=80;
d=d+1;
elseif a(i,j,k)<=255
b(i,j,k)=27;
z=z+1;
end
end
end
end
figure;
imshow(b);

답변 (1개)

Vandana Rajan
Vandana Rajan 2017년 3월 1일
Hi,
It seems that there are some problems with the conditions you are giving.
a(i,j,k)<=120 includes all values below 120, which includes values below 80 too. May be you are thinking of values between 81 and 120? In that case you need to give 80<a(i,j,k)<=120. Similarly for a(i,j,k)<=255.
  댓글 수: 2
sudarshan r
sudarshan r 2017년 3월 7일
hi,vandana rajan the IF condition you have written in the matlab as 80<a(i,j,k)<=120 is not accepted, it only allows a(i,j,k)<=120 as this way, writing the scalar value on the left side is illegal please find this.
Vandana Rajan
Vandana Rajan 2017년 3월 8일
yeah. for that you need to write (a(i,j,k)>80 && a(i,j,k)<=120). What I provided above was the logic and not the exact syntax.

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

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by