I would like to reduce the pixel value of image for each range rgb channel to [0 1], but at the end i get an endless loop

my code is :
I=imread('peppers.png');
im_red = I(:,:,1);
im_green = I(:,:,2);
im_blue = I(:,:,3);
red = double(im_red)/255;
mid_red = (max(red)-min(red))/2;
[redrow redcol]=size(red);
for i=1:redrow
for j=1:redcol
if red(i,j) > mid_red
red(i,j)=1
else red(i,j)=0
end
end
end
Please help me solve the problem

Answers (1)

red = red>mid_red
%a one liner

1 Comment

Thank for your answer.
Finally, i found my solution with change this line:
from
mid_red = (max(red)-min(red))/2;
to
mid_red = (max(red(:))-min(red(:)))/2;

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 20 Mar 2011

Community Treasure Hunt

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

Start Hunting!