Change a single pixel value in a Grayscale JPEG image
4 views (last 30 days)
Show older comments
I have a grayscale jpeg image X. I want to change its pixel value. For example change pixel at (14,20) to 1,How can I do it. I tried the following but it doesn't WORK:
Xc=X; %Xc is image with a pixel value changed from X[X is original image]
X(14,20); %What is the value at 14,20
Xc(14,20)=1 %Change Pixel value at 14,20 to 1
When i view its values in Variable Editor,I don't get value changed at (14,20) in Xc image.
What are the Errors or suggestion?
0 Comments
Accepted Answer
Thomas
on 25 Apr 2012
Are you sure you are checking Xc in the variable editor, you might be checking X (original image). the above does work..
I have tried
X=imread('1.jpg') % My image was color so was MxNxP
Xc=X(:,:,1) % crateda grayscale image MxN
Xc(14,20) % here my output was ans=129
Xc(14,20)=1 % changed the value of (14,20) to 1
Xc(14,20) % here my output was ans=1
If I change a block of values in Xc to 1 and do the imshow(Xc) - gives me a black box..
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!