RGB = imread('image.png');
Image is stored as a nxmx3 matrix, where the 3 layers are red, green and blue pixel intensity and nxm is the resolution. Find pure red colors by finding the indices with strong red channels (1st layer close to 255) and weak green/blue channels (2nd and 3rd channels clsoe to zero).
mask = RGB(:,:,1)>230 & RGB(:,:,2)<1 & RGB(:,:,3)<1;
then you can use this mask to change the colors of your image
RGB(repmat(~mask,1,1,3)) = 0;
RGB(repmat(mask,1,1,3)) = 255;