Changing pixel colors of .JPG image produces weird colors

1 view (last 30 days)
function applyGrid(app)
app.newImage = app.originalImage;
[imageWidth, imageLength] = size(app.originalImage);
imageLength = imageLength/3;
for row = imageWidth/18 : imageWidth/18 : imageWidth
app.newImage(round(row), :) = 0;
end
for col = imageLength/36 : imageLength/36 : imageLength
app.newImage(:, round(col)) = 0;
end
% display new image with grid lines to UI
app.Image.ImageSource = app.newImage;
end
This code is supposed to draw a grid onto an image. It works, but the vertical lines are blue when their value is set to 0 and red when set to 255. The horizontal lines are black at 0 and green at 255. The grid lines need to all be black. The image is a .jpg read to a property with imread().

Accepted Answer

Jonas
Jonas on 20 Jul 2022
dont forget to set all 3 channels of the rgb image to 0 by using e.g.
app.newImage(:, round(col),:) = 0
  3 Comments
Bao
Bao on 21 Jul 2022
Yeah that makes sense. Thanks for the explanation.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 20 Jul 2022
You could use line() to draw lines in the overlay above the image instead of burning them into the image arrray itself. So do you want the grid lines burned in (so the underlying image, not just the displayed image, is changed), or not?
  1 Comment
Bao
Bao on 21 Jul 2022
I want the grid lines burned in. We are making an application that is able to plot and transform a 360 degree image. It needs to be burned in so that the user can save the new image.

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by