how to recombine subimages from cell2mat?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Paul Shoemaker
am 5 Mär. 2018
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 Kommentare
Guillaume
am 5 Mär. 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.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!