I have a jpg picture which is black and white and I would like to convert black part to white and white to black( black pixel to white and vise versa ) in MATLAB
and save it as jpg file again.
I have tried this code but it just give me a black line in the white page.
im=imread('Export0000009111.jpg');
binstring = dec2bin(im, 8);
binImage = ~binstring;
binImage = 1-binImage;
binImage = (binImage == 0);
imwrite(binImage,'ss1.png');
Does anyone has any proper solution for that?
Thanks in advance!
Code -
PATHNAME = 'Random.jpg'; %// Original image file
PATHNAME1 = 'RandomModified.jpg'; %// Modified image file
imwrite(uint8(255 - imread(PATHNAME)),PATHNAME1)
figure, imshow(imread(PATHNAME1))
When you read images, normally they come in 2D or 3D matrices with values in between 0 and 255, with 0 being black and 255 being white. So, we only need to subtract every pixel value from 255. This will do your job, will create negative images for gray images and for color image would be give a sense of "colored-negative" if I could invent a term like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With