Problema al descomponer y volver a componer imagen en RGB
Show older comments
Buenos días a todos los programadores de este estupendo foro.
Soy bastante novato en Matlab, y acutualmente me encuentro realizando una pequeña aplicación donde cojo una imágen RGB, la descompongo en sus 3 matrices (R G B), modifico varios píxeles del canal B, vuelvo a unir los 3 canales y después grabo la imágen.
Todo esto funciona correctamente, pero después, al volver a abrir al imágen y volver a descomponer los valores R G B, veo que el valor que yo había modificado no es el mismo. P.ongo el trozo del código:
MSG='Hola';
Fichero='Imagen.jpg';
handles.imagen2=imread(Fichero);
R2=handles.imagen2(:,:,1);
G2=handles.imagen2(:,:,2);
B2=handles.imagen2(:,:,3);
B2(1,1)=length(MSG);
handles.ImagenCodificada(:,:,1)=R2;
handles.ImagenCodificada(:,:,2)=G2;
handles.ImagenCodificada(:,:,3)=B2;
Fichero='Imagen2.jpg';
imwrite(handles.ImagenCodificada, Fichero);
handles.ImagenCodificada2=imread(Fichero); B22=handles.ImagenCodificada2(:,:,3);
Si busco la posición B2(1,1) el valor es correcto: 4 (la longitud de la cadena 'Hola') Cuando grabo la imágen y busco B22(1,1) el valor ya no es 4 sinó 215.
He hecho un montón de pruebas y no hallo la solución... ¿Alguien me puede ayudar?
Un saludo
1 Comment
Walter Roberson
on 31 Dec 2012
Approximate translation by Google:
Good morning to all developers of this great forum.
I am fairly new to Matlab, and I find myself doing really a small application where I catch an RGB image, the matrices decompose into its 3 (RGB) amended several pixels of channel B, back to join the three channels and then recorded the image.
All this works fine, but then when you reopen the image and return to decompose RGB values, I see that I had modified value is not the same.
Here is the piece of code:
Answers (1)
Walter Roberson
on 31 Dec 2012
The JPEG image format is a "lossy" image compression, which will not return exactly the same data as was stored. Use TIFF or PNG image format instead.
Fichero='Imagen2.jpg';
becomes
Fichero='Imagen2.tif';
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!