Help with "Colorization using Optimization" method

I found this method of coloring black and white pictures and clips online, and came with a code to put into MATLAB, and please let it be known I'm new at this program, so I'm really confused. (If you want to see the original ZIP file, it's here http://www.cs.huji.ac.il/~yweiss/Colorization/ ) To sum it up, it gives me this code to input:
g_name='example.bmp';
c_name='example_marked.bmp';
out_name='example_res.bmp';
%set solver=1 to use a multi-grid solver
%and solver=2 to use an exact matlab "\" solver
solver=2;
gI=double(imread(g_name))/255;
cI=double(imread(c_name))/255;
colorIm=(sum(abs(gI-cI),3)>0.01);
colorIm=double(colorIm);
sgI=rgb2ntsc(gI);
scI=rgb2ntsc(cI);
ntscIm(:,:,1)=sgI(:,:,1);
ntscIm(:,:,2)=scI(:,:,2);
ntscIm(:,:,3)=scI(:,:,3);
max_d=floor(log(min(size(ntscIm,1),size(ntscIm,2)))/log(2)-2);
iu=floor(size(ntscIm,1)/(2^(max_d-1)))*(2^(max_d-1));
ju=floor(size(ntscIm,2)/(2^(max_d-1)))*(2^(max_d-1));
id=1; jd=1;
colorIm=colorIm(id:iu,jd:ju,:);
ntscIm=ntscIm(id:iu,jd:ju,:);
if (solver==1)
nI=getVolColor(colorIm,ntscIm,[],[],[],[],5,1);
nI=ntsc2rgb(nI);
else
nI=getColorExact(colorIm,ntscIm);
end
figure, imshow(nI)
imwrite(nI,out_name)
And I always get the error message "Subscripted assignment dimension mismatch."
Can someone please help me,
thank you

1 Comment

Please use code formatting as described by the "Markup help" link on this page. And post the line, which causes the error, that we do not have to search it.

Sign in to comment.

Answers (3)

Their MATLAB programming skills could use some improvement. Place this line:
ntscIm = zeros(size(sgI));
right before the lines:
ntscIm(:,:,1)=sgI(:,:,1);
ntscIm(:,:,2)=scI(:,:,2);
ntscIm(:,:,3)=scI(:,:,3);
and it should work.
Hello Dr.Es .Cargoon
I need code for this conversion in matlab. The code which i found in the above link is is c++ also.I need only in matlab.
Add this line: ntscIm=sgI(:,:,1)+scI(:,:,2)+scI(:,:,3); before this: ntscIm(:,:,1)=sgI(:,:,1); ntscIm(:,:,2)=scI(:,:,2); ntscIm(:,:,3)=scI(:,:,3);
I had to get add on MinGW in Matlab to compile the c programs, then write the line in command window: >>mex -O getVolColor.cpp fmg.cpp mg.cpp tensor2d.cpp tensor3d.cpp
later i had to open the .h files and replace < iostream.h> with < iostream>

Tags

Asked:

on 15 Oct 2011

Answered:

on 25 Mar 2018

Community Treasure Hunt

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

Start Hunting!