How to replace image pixels

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 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2019 年 8 月 5 日

回答済み:

2019 年 8 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by