Converting CMYK JPG to RGB JPG

23 visualizaciones (últimos 30 días)
Jacob Mevorach
Jacob Mevorach el 31 de Mzo. de 2017
Comentada: Abdurrahman Tosun el 5 de Oct. de 2019
So if I detect a CMYK image I have a script written that attempts to convert the image to an RGB image so I can use imread on it (CMYK is not supported by imread for jpgs) and then tries to sharpen the image and convert it to black and white. Unfortunately the way I'm using applycform is not working and I keep getting an error that says "Cform structure is invalid for Named Color". Does anyone know anyway I might be able to resolve this or convert detect CMYK images to RGB images? All the Best!
inprof = iccread('USSheetfedCoated.icc');
outprof = iccread('sRGB.icm');
C = makecform('icc',inprof,outprof);
for i=1:numFiles2
info=imfinfo(fullfile(workingDirectory,imageFiles2(i).name));
if info.ColorType == 'CMYK'
fullfile(workingDirectory,imageFiles2(i).name) = applycform(fullfile(workingDirectory,imageFiles2(i).name),C);
end
frame = imread(fullfile(workingDirectory,imageFiles2(i).name));
frame = imsharpen(frame);
gray = rgb2gray(frame);
imwrite(gray,imageFiles2(i).name);
end

Respuesta aceptada

Carl
Carl el 3 de Abr. de 2017
Editada: Carl el 3 de Abr. de 2017
Hi Jacob, the first input to the 'applycform' function needs to be a matrix of the image data, rather than the path to the file itself. You are passing in a character vector for that argument, so the function assumes that you are using a named color profile, and errors out accordingly since the encoding 'C' from 'makecform' does not match.
Since 'imread' does not support CMYK JPG files in the first place, this puts us in a tricky situation. What you really need to do, is perform the conversion before being able to work with it at all in MATLAB. There are third-party tools that would allow you to do this conversion.
  6 comentarios
Soan Duong
Soan Duong el 14 de Ag. de 2018
Hi @Image Analyst, I used the imfinfo() function to read the information of my image. The ColorType is CMYK.
Besides, when I read the image by imread() function, and I got an error of JPEG images with CMYK colorspace are not currently supported.
The two reasons make me think the image is CMYK. I just receive images and do not know what program created them.
Abdurrahman Tosun
Abdurrahman Tosun el 5 de Oct. de 2019
it is very easy to save this position. save to your image at paint program, after that convert to jpeg again by using paint program :) if this save you please let me know

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by