function labelMonth(monthData) % function labelMonth(monthData) % % allows a user to look at the images of a month and choose them for labelling; % results are stored in 'month_labels.mat' % % Inputs % monthData: an M by N by d matrix, where d is the number of images - each image size M by N load 'month_labels'; [M, N, numImages] = size(monthData); mod = zeros(N, M, numImages); for a = 1 : numImages % create correct images mod(:, :, a) = rot90(monthData(:, :, a) + 1); end largest_x = M; largest_y = N; border = round(largest_y / 6); % desired total mosaic image ratio of x to y ratio = 1.3; %calculate desired size of each slice image x = sqrt(ratio * numImages * largest_y / largest_x); x = round(x); y = ceil(numImages / x); % build mosaic of images mosaic = []; imageCount = 1; chipX = largest_x + 2*border; chipY = largest_y + 2*border; for i = 1 : y row = []; for j = 1 : x chip = ones(chipY, chipX) * 20; if (imageCount <= numImages) reducedIm = mod(:, :, imageCount); [lenY, lenX] = size(reducedIm); space_x = round((largest_x - lenX)/2); space_y = round((largest_y - lenY)/2); chip(border + space_y + 1 : border + space_y + lenY, border + space_x + 1 : border + space_x + lenX) = reducedIm; % add white bar under image if it has not been labeled if (isempty(month_labels(imageCount).first) & isempty(month_labels(imageCount).second) & isempty(month_labels(imageCount).third) & isempty(month_labels(imageCount).fourth)) chip(chipY - 6 : chipY - 3, round(chipX/2) - 10 : round(chipX/2) + 10) = 200; end end row = [row, chip]; % disp(['Adding image ', num2str(imageCount), ' to mosaic.']); imageCount = imageCount + 1; end mosaic = [mosaic; row]; end % display mosaic imagesc(mosaic); title('Choose an image to label, or hit enter to exit. All images with a red bar have not been labelled.'); updated = 'Label results stored to month_labels.mat for images:'; % allow user to select images for labelling while (1 == 1) [xPos, yPos, b] = ginput(1); if (isempty(b)) break; end xPos = round(xPos); yPos = round(yPos); % compute image number selected x_chip_select = ceil(xPos / chipX); y_chip_select = ceil(yPos / chipY); chip_select = (y_chip_select - 1) * x + x_chip_select; % get labeled information and modify month_labels label_struct = labelImage(flipud(mod(:, :, chip_select))); month_labels(chip_select) = label_struct; updated = strcat(updated, ' #', num2str(chip_select)); % remove white bar from underneath image that was just labeled mosaic(chipY * y_chip_select - 6 : chipY * y_chip_select - 3, chipX * (x_chip_select - 1) + round(chipX/2) - 10 : chipX * (x_chip_select - 1) + round(chipX/2) + 10) = 20; imagesc(mosaic); title('Choose an image to label, or hit enter to exit. All images with a red bar have not been labelled.'); end save 'month_labels' month_labels; disp(' '); disp(updated); disp(' '); close;