changing the rgb values of the pixels in a jpg image

3 ビュー (過去 30 日間)
roshana
roshana 2011 年 4 月 6 日
編集済み: Walter Roberson 2017 年 7 月 16 日
J=imread('A.jpg');
for i=1:r
for j=1:c
J(i,j,1)=newrgb(1,1);
J(i,j,2)=newrgb(1,2);
J(i,j,3)=newrgb(1,3);
end
end
%%newrgb is a matrix with 3 rgb values.
when I check the newrgb matrix, it has double values larger than one,i guess 1 to 255.
I know imread gives me values of uint8, but i tried converting the newrgb values to uint8, or even converting the rgb of my image to double, but the result is a white picture, what should i do?
thank you
  1 件のコメント
Poornakant
Poornakant 2017 年 7 月 15 日
Hello Roshana, I'm working on something similar to this question of yours. Changing the RGB values of a pixel to get a specific curve of an image. I'm new to MATLAB coding could you please help me with the method you've used to sort your problem. Thank you.

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

回答 (3 件)

Walter Roberson
Walter Roberson 2011 年 4 月 6 日
Replace your 3 existing assignments with
J(i,j,:) = newrgb .* 255;
  2 件のコメント
roshana
roshana 2011 年 4 月 6 日
still not working. you see the rgb values of J are in uint8.when I divide the newrgb values by 255, instead of multiplying, it gives me a maroon picture. in case of multiplying it is only a white page
Walter Roberson
Walter Roberson 2011 年 4 月 6 日
What value range is newrgb ? And what data class is the variable?

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


roshana
roshana 2011 年 4 月 7 日
newrgb values are between 1 to 100, and of type double.
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 4 月 7 日
If J is uint8 and your newrgb values are in the range you indicate, then your original code will set the entire block J(1:r,1:c,:) to be the color indicated by newrgb. If r and c are the size of J then the result would be a monochrome picture. If the values in newrgb are all the same, then the monochrome picture would be a shade of gray.
After you assign the values, look at J(1,1,:) to see whether the values match the (rounded) values of newrgb .

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


roshana
roshana 2011 年 4 月 7 日
the problem is solved. it seems matlab kept the previous wrong answer in the memory in a way. I came to know this when I changed my image, the result was still the previous image, I totally changed the variable, and it works. Maybe because I used J as image variable, and j as the loop variable ...
Thank you

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by