Red, Green, Blue Full image pattern file's RGB value distortion when patterns was saved to jpg file form.

2 visualizzazioni (ultimi 30 giorni)
Hello,
I met the problem that is RGB full image pattern file's RGB value distortion at jpg file.
I want to make the specific color box pattern that have background and center box. and this file must be jpg file.
but when I run this code to make perfect red pattern(255, 0, 0) and verify this is right color,
the red pattern file had RGB value of (254, 0, 0) .
Could you tell me how to generate perfect red(255,0,0 / jpg file)?
also I try to imwirte(img, filename, 'Quality', 100), however this problem was not cleared.
and equally if I make perfect green and blue, this green have (0, 255, 1) / blue have (0, 0, 254).
Please, Note below the function code:
function value = fullimage(image_values, V, H)
for i = 1: size(image_values, 1)
% CSV 파일 내 데이터를 한 줄씩 가져오는 작업
image_values_row = image_values(i,1:7); %수정 Point2
% CSV 파일 내 한 줄의 데이터 내에서 각 필요한 데이터를 하나씩 추출
R = image_values_row(1); %R value of RGB
G = image_values_row(2); %G value of RGB
B = image_values_row(3); %B value of RGB
BS = image_values_row(4);
BGR = image_values_row(5); %Back ground R value of RGB
BGG = image_values_row(6); %Back ground G value of RGB
BGB = image_values_row(7); %Back ground B value of RGB
% CSV 파일 내 색상 RGB 값을 통해 BackGround에 RGB값 지정
img(1:V, 1:H, 1) = BGR/255;
img(1:V, 1:H, 2) = BGG/255;
img(1:V, 1:H, 3) = BGB/255;
% Box size에 따라 내부에 Box가 생성되도록 하는 수식, 양의 정수 범위어야함.
Vbox1 = round(V/2-sqrt(BS)/20*V)+1;
Vbox2 = round(V/2+sqrt(BS)/20*V)+1;
Hbox1 = round(H/2-sqrt(BS)/20*H)+1;
Hbox2 = round(H/2+sqrt(BS)/20*H)+1;
% CSV 파일 내 색상 RGB 값을 통해 Box에 RGB값 지정
img(Vbox1:Vbox2, Hbox1:Hbox2, 1) = R/255;
img(Vbox1:Vbox2, Hbox1:Hbox2, 2) = G/255;
img(Vbox1:Vbox2, Hbox1:Hbox2, 3) = B/255;
%이미지 저장
filename = sprintf('image%d.jpg',i);
imwrite(img,filename);
end
end
  2 Commenti
Angelo Yeo
Angelo Yeo il 16 Feb 2023
문제를 재현할 수 있도록 예시 파일과 예시 스크립트를 올려주실 수 있으실까요? 함수 스크립트만 가지고는 어떤 이슈인지 정확히 알기 어렵습니다.
JUNHYEONG KIM
JUNHYEONG KIM il 16 Feb 2023
Okay, Please note below the example code that will generate same phenomenon.
if you run this code, the red pattern's RGB value is (254,0,0), not (255,0,0)
I want to get (255,0,0) image [jpg file form]
% setting Horizontal, Vertical pixels
H = 1920;
V = 1080;
R = 255;
G = 0;
B = 0;
% Setting RGB Value
img(1:V, 1:H, 1) = R/255;
img(1:V, 1:H, 2) = G/255;
img(1:V, 1:H, 3) = B/255;
% Save image
filename = sprintf('image1.jpg');
imwrite(img,filename)

Accedi per commentare.

Risposta accettata

Angelo Yeo
Angelo Yeo il 16 Feb 2023
imwrite(img,filename,'mode','lossless')
  4 Commenti
Angelo Yeo
Angelo Yeo il 16 Feb 2023
Modificato: Angelo Yeo il 16 Feb 2023
작성해주신 예시 스크립트를 수정해보면 정상적으로 255 값이 저장되는 것을 알 수 있습니다.
% setting Horizontal, Vertical pixels
H = 1920;
V = 1080;
R = 255;
G = 0;
B = 0;
% Setting RGB Value
img(1:V, 1:H, 1) = R/255;
img(1:V, 1:H, 2) = G/255;
img(1:V, 1:H, 3) = B/255;
% Save image
filename = sprintf('image1.jpg');
imwrite(img,filename,'mode','lossless')
a = imread('image1.jpg');
a(1,1,1)
ans = uint8 255
위의 스크립트가 사용하시는 MATLAB 환경에서 동작하는지 우선 확인 부탁드립니다. "죄송합니다. 현재 지원되지 않는 형식이거나 파일이 손상되었기 때문에 사진을 열 수 없습니다"와 같은 에러가 발생하는 이유는 다른 원인에 의한 것은 아닐까요?
JUNHYEONG KIM
JUNHYEONG KIM il 20 Feb 2023
계속 자세하게 답변 주셔서 감사합니다.
다만, Angelo Yeo님께서 답변해주신 부분은 틀린 점은 없으나, jpg 파일에 mode - lossless 기능을 적용하면 실제 이미지 파일 실행에 있어서는 실행이 제대로 되지는 않는 것으로 보입니다.
이에 따라 다른 부분에서 검토를 진행해봤습니다.
그 결과 Photoshop으로 동일하게 Red 패턴을 형성했을 때 (254,0,0)으로 RGB 값이 확인되는 것을 볼 수 있었습니다. 즉 jpg 파일 자체가 가진 한계성이라고 생각이 됩니다.
충분히 답변이 된 것 같습니다. 함께 검토해주셔서 다시 한 번 감사합니다.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!