how to recombine subimages from cell2mat?
Show older comments
i have taken grayscale image which is converted into window size of 8x8 by using mat2cell.then later i have to get back original image from cell2mat which i am finding it difficult to do?
a=VideoReader('test.mp4 ');
b = read(a,1 );
c=rgb2gray(b );
nframe=a.NumberOfFrames ;
for i=115:116
prev_frame =read(a,i-1 );
e=rgb2gray(prev_frame );
figure
imshow(e );
pause(0.2)
current_frame =read(a,i);
h=rgb2gray(current_frame );
figure
imshow(h);
rows = 8 ;
columns = 8 ;
[H,W,~] = size(c );
szH = [repmat(fix(H/rows),1,rows )];
szW = [repmat(fix(W/columns),1,columns )]; //to split into window size of 8x8 as per my algorithm
C = mat2cell(e, szH, szW )';
D = mat2cell(h, szH, szW )';
figure
for j=1:rows*columns
subplot(rows,columns,j), imshow( C{j } ) //to plot above cells
end
figure
for j=1:rows*columns
subplot(rows,columns,j), imshow( D{j } )
end
for k=1:1*8
o=1:1*8
G=cell2mat(C(k,o)');
figure
imshow(G);at this point i am getting images which i am not able to recombine.kindly suggest something here
end
for k=1:8
o=1:8
H=cell2mat(D(k,o)');
figure
imshow(H);
end
w=std(double(G));
figure
plot(w);
b=std(double(H));
figure
plot(b);
level=graythresh(G);
level=graythresh(H);
if level>level1
T=im2bw(G);
figure
imshow(T);
else
P=im2bw(H);
figure
imshow(P);
end
end
kindly suggest some code or technique to do?
4 Comments
Guillaume
on 5 Mar 2018
Besides the points highlighted in Paul's answer below, and the unreadable nature of your post (edit your post, get rid of the blank lines you probably painstakingly inserted, select all the code, then click the {}Code button), you need to explain your problem more clearly.
What are you trying to recombine? What is the expected output?
Guillaume
on 5 Mar 2018
i should get back same image
Which image? The badly named e that you've split in the badly named C? The badly named h that you've split in the badly named D? Some other image?
Since you haven't modified any image after splitting them why can't you use the original image.
Note that your
o=1:1*8
H=cell2mat(D(k,o)'); %For pete's sake use better variable names than just going through the alphabet!
can be rewritten more simply as
H = [D{k, :}];
and also note that 1*8 is just 8.
However, I'm not sure why I'm commenting. Since you've accepted an answer, your problem is obviously resolved.
ramya
on 7 Mar 2018
ramya
on 7 Mar 2018
Answers (1)
Paul Shoemaker
on 5 Mar 2018
0 votes
It's a bit difficult to read your code above. If you follow-up with more code, try highlighting the code portion of your post and selecting the "Code" option/button in the Matlab forum formatting menu to make it more legible.
However, when I paste it into Matlab and format, it would appear that you are re-defining "i" within the FOR loop. In other words, you have a FOR loop that loops over i, but then you appear to have another FOR loop within that one that also loops over i. If I'm seeing this correctly, then this will definitely lead to problems and may be the source of what you're seeing.
Paul Shoemaker
2 Comments
Guillaume
on 5 Mar 2018
Actually, in this code because the outer i is only used before the inner i loop, it will not cause any issue. But yes, this is a really bad idea to have the same index variable in inner loops.
In fact, apart from nframe, rows and columns all the variables are badly named, giving no indication of their purpose. It looks like the OP is just going through the alphabet.
Using meaningful variable names goes a long way towards documenting the purpose of the code.
ramya
on 5 Mar 2018
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!