Filter löschen
Filter löschen

Save one image as part of a larger image

1 Ansicht (letzte 30 Tage)
Susan
Susan am 10 Mai 2012
Hi all,
I have processed image data into a 10x512 pixel array. I have multiple images all this size and I would like to display them all side by side on a single larger image. I have created a blank image using zeros of size 1000x512 (i.e. I have 100 images in total, therefore 10 pixels x 100 images) but am having trouble getting my smaller image to display. How could I approach this?
Kind regard and thanks, Susan

Akzeptierte Antwort

Geoff
Geoff am 10 Mai 2012
Let's just assume that all your images are in a 3D matrix and you want to slap them onto a canvas:
canvas = zeros(1000, 512); % Target image
images = rand(10, 512, 100); % 100 very useless images =)
Now, in this case, there are clever MatLab functions, but I'll stick to a simple loop so you see what's going on (and that's adaptable if your images are stored in some other way).
for n = 1:100
rows = (n-1) * 10 + (1:10);
canvas(rows, :) = images(:,:,n);
end
So, for each image (indexed by n), you calculate a range of row indices for your 10 rows. The value (n-1) * 10 gives the zero-based position of the first row of the 'n'th image, and then you add that to the vector 1:10. ie image 1 is rows 1:10, image 2 is rows 11:20, etc...
The slice canvas(rows, :) is then a 10-by-512 address, into which you assign the values from your 'n'th image (also 10-by-512).
  1 Kommentar
Susan
Susan am 15 Mai 2012
Hi Geoff,
Thanks for your reply - I adopted your method and it works!! :)
However, I've still a problem. I'm processing 500 images in total - 10 (i_B in code) groups of 50 (num_A in code) - producing an image for each iteration of i_B (yielding 10 images in total of pixel size (N,50)). The code works fine if I set i_B = 1, 2, 3, etc. manually but I would like to automate it (so that the code will output and save 10 images in this case) as I will have a larger number of images in the future. The error I am getting is:
??? Subscripted assignment dimension mismatch
at the portion of the code below indicated by ******.
I would greatly appreciate any advice!
Kind regards,
Susan
P.s. I've omitted some of the preceding code for clarity (will not affect operation)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num_B = 10
num_A = 50;
for i_B = 1:num_B
for i = 1:num_A
file = sprintf('%s%s%d%s',folder,filename,((100*(i_B-1))+1+(2*(i-1))),suffix);
A = imread(file);
mA = mean(A);
mA(1) = mA(2);
fit = polyfit(nm,mDC,4);
pDC = polyval(fit,nm);
S = mA./pDC;
S = S - mean(S);
Ses = interp1(nu,S,kes);
abs_s_tau = abs(fft(Ses));
img(:,i) = abs_s_tau'; ******
end
img = img(1:(pixel/2),:);
img = log10(img);
img = mat2gray(img);
img = img(1:pixel/2,:);
figure(i_B); clf
imshow(img);
file_saved = strcat(folder,'B-scan_',num2str(i_Bscan),'.png');
imwrite(img, file_saved ,'png', 'BitDepth', 16);
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Susan
Susan am 15 Mai 2012
Just cracked it myself. Simple mistake. Needed to initialise the image inside the first for loop. :)
num_B = 10
num_A = 50;
for i_B = 1:num_B
img = zeros(pixel,num_A);
img(i_B);
for i = 1:num_Ascans
.
.
.
.
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by