how to recombine subimages from cell2mat?

1 Ansicht (letzte 30 Tage)
ramya
ramya am 5 Mär. 2018
Bearbeitet: ramya am 7 Mär. 2018
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
ramya
ramya am 7 Mär. 2018
as per the algorithm there is need to split and perform operations on them and then later again recombine it to find other parameters.......the original image i have taken at the beginning that i have to get back......and its not the one frame i have to simulate...i have approx 20 frames and so for sure there will be the difference as compared to original image based on threshold and other parameters........and this is just a draft code ..in main code for sure i will add valid names...this s as per my convenience i have variables names like this
ramya
ramya am 7 Mär. 2018
so simulate and let me know any errors....s there any other command other than cell2mat to recombine all 8x8 images again into one image which i have got from mat2cell? and please check from here imshow(G); here only i am stuck which is affecting the desired output

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Paul Shoemaker
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
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.
ramya
ramya am 5 Mär. 2018
i have done the modification and i should get back same image which i had read at the starting(bw) but based on graythresh value whereas i am getting a single strip.suggest something in this?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by