Compute negative image processing pixel by pixel

Hi, so I just started using MATLAB, and I need to solve this exercise: "iven a 24bpp Image, write a MATLAB code to compute the "negative image". The solution must reach the result by processing pixel by pixel." I assume I have to use a for loop to process pixel by pixel; til now, I found this possible solution:
>> a = imread('nameOfTheImage.png');
>> d(:,:,3) = 255 - a(:,:,3);
>> d(:,:,2) = 255 - a(:,:,2);
>> d(:,:,1) = 255 - a(:,:,1);
>> imshow([a,d])
but I think it's too simple. Can you help me with some indications? Thank you in advance!

 採用された回答

Rik
Rik 2017 年 10 月 28 日

2 投票

Congratulation, you came up with a better solution than the one your instructor asked you. You can even make this one shorter:
a = imread('nameOfTheImage.png');
d=255-a;
But you needed to use a loop to access each pixel separately:
d=a;
for row=1:size(a,1)
for col=1:size(a,2)
d(row,col,:)=255-a(row,col,:);
end
end

4 件のコメント

Giorgio Gurian
Giorgio Gurian 2017 年 10 月 29 日
Thank you very much, this seems like the best solution, considering the request!
Giorgio Gurian
Giorgio Gurian 2017 年 10 月 29 日
Also, can you give me a description of what every line of code does? Thanks!
Rik
Rik 2017 年 10 月 29 日
You can open up the documentation with the doc command. There you can look at what the for and size functions do.
Giorgio Gurian
Giorgio Gurian 2017 年 10 月 29 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

質問済み:

2017 年 10 月 28 日

コメント済み:

2017 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by