How to write an if-else statement for this condition in MATLAB?
Show older comments
for each pixel, do
if R>90 & R>G & R>B
classify the pixel as **Healthy**
else
classify the pixel as non-healthy
I am trying to implement an algorithm which reads a skin lesion image and after extracting the R, G, and B values, it classifies the lesion into healthy skin or non-healthy skin based on the if condition
However, when I try to implement it, only the non-healthy skin array is getting updated inside the for loop and the healthy skin array remains zero. I do not know how to overcome this glitch. Please help.
hs=zeros(m,n); %initialising heaklthy skin array
nhs=zeros(m,n); %initialising non-healthy skin array
R=colorSkin(:, :, 1);
G=colorSkin(:, :, 2);
B=colorSkin(:, :, 3);
for i = 1:m
for j = 1:n
if R>90&R>B&R>G
hs(i, j)= colorSkin(i, j);
else
nhs(i,j)=colorSkin(i,j);
end
end
end
1 Comment
GEEVARGHESE TITUS
on 21 Feb 2017
Basically the indexing of the R, G, B plane was missing in the if loop. Just added a few more lines and changed the type of the output variables,to verify whether the code is working.
sk=imread('skincancer1.jpg');
[m n dim]=size(sk);
hs=zeros(m,n); %initialising heaklthy skin array
nhs=zeros(m,n); %initialising non-healthy skin array
R=sk(:, :, 1);
G=sk(:, :, 2);
B=sk(:, :, 3);
for i = 1:m
for j = 1:n
if R(i,j)>150&R(i,j)>180&R(i,j)>B(i,j)&R(i,j)>G(i,j)
hs(i, j)= sk(i, j);
else
nhs(i,j)=sk(i,j);
end
end
end
imshow(uint8(nhs))
title('normal');
figure;imshow(uint8(hs))
title('cancer');Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

