How to replace image pixels

조회 수: 29 (최근 30일)
sejugn jung
sejugn jung 2019년 8월 5일
답변: Image Analyst 2019년 8월 5일
I have an image and a csv file. I want to change the pixel value of the image to the values in the csv file. How do I do that?
  댓글 수: 1
Adam
Adam 2019년 8월 5일
Load the image, load the csv file, index into the image and replace values. Write the image to file again if desired.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2019년 8월 5일
Try this if your data is stored row, column, new gray level:
data = csvread(filename); % Assumes columns of row, column, new gray level, NOT x, y, new gray level
rows = data(:, 1);
columns = data(:, 2);
newValues = data(:, 3);
for k = 1 : length(rows)
grayImage(rows(k), columns(k)) = newValues(k); % Replace this pixel of grayImage with a new value.
end
If your data is in the form x, y, gray level, you need to do this:
data = csvread(filename); % Assumes columns of x, y, new gray level, NOT row, column, new gray level
rows = data(:, 2);
columns = data(:, 1);
newValues = data(:, 3);
for k = 1 : length(rows)
grayImage(rows(k), columns(k)) = newValues(k); % Replace this pixel of grayImage with a new value.
end

카테고리

Help CenterFile Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by