how to delete the white pixel(255) from grey scale image

I have to delete only 225 value white pixel from gray scale image. But i don't know how to identified each pixel from image and check if it is 255 and assign it's value to zero. Please help me

 Accepted Answer

im(im==255)=0

11 Comments

how to check the pixel value of each cell?
You can use a for loop, but depending on what you want you can avoid it
[n,m]=size(im) % im is your image nxm array
for ii=1:n
for jj=1:m
x=i(ii,jj) % your pixel at coordinate (ii,jj)
% do
end
end
function W = Classify(ImageRead)
% Step 1: Read image Read in
RGB = imread('E:\Working\mapping\first\map.png');
figure,
imshow(RGB),
title('Original Image');
% Step 2: Convert image from rgb to gray
GRAY = rgb2gray(RGB);
g=GRAY;
imtool(GRAY);
title('Gray Image');
[r c]=size(g);
for i=1:r
for j=1:c
if (impixel(g,j,i)>254)
{
g(i,j)=0;
}
end
end
end
figure,
imshow(z);
I am getting error like below
Error: File: maping.m Line: 20 Column: 23 The expression to the left of the equals sign is not a valid target for an assignment.
What are the symbols { and } , you are not programming with c, it's Matlab!
can you please tell the correct expression for assign the 0 value to the matrix of the image?
i have gray scale image. and i saved it in A. i want to convert white pixel(255) into black(0). So the condition is If pixel val is equal to 255 it turns into zero.
This is my program. It has major error, which i don't know.If i run this program matlab stop working.
function W = Classify(ImageRead) % Step 1: Read image Read in RGB = imread('E:\Working\mapping\first\map.png'); figure, imshow(RGB), title('Original Image');
% Step 2: Convert image from rgb to gray GRAY = rgb2gray(RGB); g=GRAY; imtool(GRAY); title('Gray Image');
[r c]=size(g); hold on for i=1:r for j=1:c if (impixel(g,j,i)>254)
GRAY(i,j)=0;
end
end
end
hold off
imtool(GRAY);
Why do you have both g and GRAY? You don't need two. And we're back to Azzi's original answer
g(g==255)=0;
GRAY(GRAY==255)=0;
Why didn't you follow his advice instead of doing things with for loops and two copies of the same image?

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type 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!