Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số

78 16 0
Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số Nghiên cứu và phát triển phương pháp nâng cao độ phân giải ảnh số

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI HOÀNG VIỆT HOÀNG VIỆT NGHIÊN CỨU VÀ PHÁT TRIỂN PHƯƠNG PHÁP NÂNG CAO ĐỘ PHÂN GIẢI ẢNH SỐ CÔNG NGHỆ THÔNG TIN LUẬN VĂN THẠC SĨ KỸ THUẬT Công nghệ Thông tin GIẢNG VIÊN HƯỚNG DẪN TS LÃ THẾ VINH 2014B Hà Nội - 2017 MỤC LỤC LỜI CAM ĐOAN DANH MỤC CÁC THUẬT NGỮ, CHỮ VIẾT TẮT DANH MỤC HÌNH MỞ ĐẦU CHƯƠNG - TỔNG QUAN VỀ SIÊU PHÂN GIẢI ẢNH SỐ 1.1 Ảnh số 1.1.1 Khái niệm ảnh số 1.1.2 Độ phân giải ảnh số .8 1.2 Siêu phân giải ảnh số 1.3 Một số phương pháp siêu phân giải ảnh số .10 1.3.1 Siêu phân giải dựa sở liệu bên 10 1.3.2 Siêu phân giải dựa sở liệu nội 10 CHƯƠNG – THUẬT TOÁN SIÊU PHÂN GIẢI DỰA TRÊN 12 CÁC MẪU TỰ THÂN BIẾN ĐỔI 12 2.1 Giới thiệu thuật toán 12 2.2 Mở rộng khơng gian tìm kiếm patch nội 13 2.3 Phát mặt phẳng 14 2.4 Thuật toán lân cận gần gần (thuật toán PatchMatch) 17 2.4.1 Khởi tạo .18 2.4.2 Quá trình lặp .18 2.5 Thuật toán siêu phân giải dựa mẫu tự thân biến đổi 20 2.5.1 Tổng quan 20 2.5.2 Ước lượng trường lân cận gần 23 2.5.2.1 Hàm mục tiêu 23 2.5.2.2 Suy luận 27 CHƯƠNG – CÀI ĐẶT, THỬ NGHIỆM VÀ ĐÁNH GIÁ THUẬT TOÁN SIÊU PHÂN GIẢI DỰA TRÊN CÁC MẪU TỰ THÂN BIẾN ĐỔI 28 3.1 Giới thiệu MATLAB 28 3.2 Cài đặt thuật toán MATLAB 29 3.2.1 Trích xuất mơ hình mặt phẳng từ ảnh 29 3.2.2 Tính tốn trước mơ hình mặt phẳng 31 3.2.3 Tổng hợp dựa patch sử dụng thuật toán PatchMatch 31 3.2.4 Khởi tạo trường lân cận gần .33 3.2.5 Ước lượng trường lân cận gần sử dụng thuật toán PatchMatch .34 3.2.6 Tính tốn chi phí xuất 35 3.2.7 Tính tốn chi phí mặt phẳng 36 3.2.8 Ước lượng gần tỷ lệ từ phép biến đổi homography sử dụng khai triển Taylor bậc .37 3.2.9 Thực lan truyền tìm kiếm ngẫu nhiên vòng lặp 37 3.3 Tập liệu thử nghiệm .37 3.4 Các thuật toán tham gia đánh giá 37 3.5 Đánh giá chất lượng 38 3.6 Đánh giá định lượng 45 3.7 Hạn chế .46 KẾT LUẬN 48 TÀI LIỆU THAM KHẢO 49 PHỤ LỤC – CÀI ĐẶT CHI TIẾT THUẬT TOÁN .50 LỜI CAM ĐOAN Tôi xin cam đoan luận văn cơng trình nghiên cứu riêng tơi có giúp đỡ lớn thầy hướng dẫn TS Lã Thế Vinh Các nội dung nghiên cứu, kết đề tài trung thực chưa cơng bố hình thức trước Trong luận văn, tơi có tham khảo đến số tài liệu liệt kê phần Tài liệu tham khảo cuối luận văn; tài liệu tham khảo trích dẫn trung thực luận văn Hà Nội, ngày… tháng … năm 2017 Tác giả Hoàng Việt DANH MỤC CÁC THUẬT NGỮ, CHỮ VIẾT TẮT Ký hiệu Tiếng Anh SR Super-resolution LR Low-resolution HR High-resolution PSNR Peak signal-to-noise ratio SSIM Structural similarity index DANH MỤC HÌNH Hình 1.1 Giảm độ phân giải giữ nguyên kích thước ảnh Hình 1.2 Giảm độ phân giải giữ nguyên kích thước điểm ảnh Hình 2.1 Ví dụ mẫu tự tương đồng bị biến dạng 13 Hình 2.2 Phát điểm hội tụ .14 Hình 2.3 Cục hóa mặt phẳng vùng biết 16 Hình 2.4 Bản đồ xác suất hậu nghiệm .16 Hình 2.5 Các bước thuật tốn lân cận gần ngẫu nhiên 17 Hình 2.6 Mô tả hội tụ 19 Hình 2.7 So sánh cách tiếp cận với thư viện thư viện nội 21 Hình 2.8 Các ví dụ minh họa cần thiết phải sử dụng mẫu tự thân biến đổi 23 Hình 2.9 Phát điểm hội tụ Bản đồ xác suất hậu nghiệm mặt phẳng 25 Hình 3.1 Giao diện MATLAB 28 Hình 3.2 So sánh kết siêu phân giải 4x .40 Hình 3.3 So sánh kết siêu phân giải 4x .41 Hình 3.4 So sánh kết siêu phân giải 4x .42 Hình 3.5 So sánh kết siêu phân giải 3x .43 Hình 3.6 So sánh kết siêu phân giải 3x .44 Hình 3.7 Kết đánh giá định lượng .45 Hình 3.8 Một trường hợp thất bại với hệ số siêu phân giải 4x 46 MỞ ĐẦU Hiện nay, việc nâng cao độ phân giải ảnh số (siêu phân giải) vấn đề quan tâm lĩnh vực xử lý ảnh ứng dụng nghiên cứu khoa học đáp ứng nhu cầu thực tế đời sống người, thuật tốn siêu phân giải dựa tự tương đồng chứng minh cho kết khả quan mà không cần thiết phải huấn luyện sâu sở liệu bên Các thuật toán khai thác vùng ảnh nhỏ (patch) có xu hướng lặp lại nhiều lần tồn ảnh Tuy nhiên, chúng có hạn chế từ điển nội thu từ ảnh thường không đủ lớn để chứa đầy đủ mẫu biến thể xuất khung cảnh Trong luận văn “Nghiên cứu phát triển phương pháp nâng cao độ phân giải ảnh số” này, nghiên cứu đề xuất xây dựng thuật toán siêu phân giải ảnh số dựa mẫu tự thân biến đổi, mở rộng khơng gian tìm kiếm patch nội cách sử dụng phép biến đổi hình học CHƯƠNG - TỔNG QUAN VỀ SIÊU PHÂN GIẢI ẢNH SỐ 1.1 Ảnh số 1.1.1 Khái niệm ảnh số Ảnh số ảnh điện tử chụp từ khung cảnh quét từ văn Ảnh số lấy mẫu chia thành lưới điểm ảnh Mỗi điểm ảnh thể màu (hoặc mức xám ảnh đen trắng) điểm ảnh biểu diễn mã nhị phân Mã nhị phân điểm ảnh lưu trữ máy tính thường nén 1.1.2 Độ phân giải ảnh số Khi lấy mẫu ảnh, ta thu nhiều điểm ảnh ảnh chi tiết Mật độ điểm ảnh ảnh gọi độ phân giải ảnh Độ phân giải cao ảnh thể rõ chi tiết chân thực, sắc nét Nếu ta giữ nguyên kích thước ảnh nâng độ phân giải lên ảnh sắc nét chi tiết Nói cách khác, với ảnh có độ phân giải cao hơn, ta hiển thị ảnh lớn với mức độ chi tiết Hình 1.1 minh họa điều xảy ta giảm độ phân giải ảnh giữ ngun kích thước nó: điểm ảnh to ảnh sắc nét, chi tiết Hình 1.1 Giảm độ phân giải giữ ngun kích thước ảnh Cịn ta giảm độ phân giải ảnh giữ ngun kích thước điểm ảnh ảnh nhỏ mức độ chi tiết (trên đơn vị diện tích) khơng đổi: Hình 1.2 Giảm độ phân giải giữ nguyên kích thước điểm ảnh 1.2 Siêu phân giải ảnh số Siêu phân giải (Super-resolution) ảnh số lớp kỹ thuật nhằm nâng cao độ phân giải ảnh số Các kỹ thuật thường sử dụng ứng dụng xử lý ảnh kính hiển vi siêu phân giải % Update uvTformA uvTformA_L = sr_uvMat_from_uvMap(NNF_L.uvTformA.map, uvPixL.ind); NNF_H.uvTformA.data = uvTformA_L; NNF_H.uvTformA.map = zeros(NNF_H.imgH, NNF_H.imgW, 4, 'single'); NNF_H.uvTformA.map = sr_update_uvMap(NNF_H.uvTformA.map, NNF_H.uvTformA.data, NNF_H.uvPix.ind); % ========================================================================= % Initialize bias for patch matching % ========================================================================= uvBias = sr_uvMat_from_uvMap(NNF_L.uvBias.map, uvPixL.ind); NNF_H.uvBias.map = zeros(imgH_H, imgW_H, 3, 'single'); NNF_H.uvBias.map = sr_update_uvMap(NNF_H.uvBias.map, uvBias, NNF_H.uvPix.ind); NNF_H.uvBias.data = reshape(uvBias, 1, 3, NNF_H.uvPix.numUvPix); % ========================================================================= % Initialize cost for patch matching % ========================================================================= NNF_H.uvCost.map = zeros(imgH_H, imgW_H, 'single'); NNF_H.uvCost.data = sr_uvMat_from_uvMap(NNF_L.uvCost.map, uvPixL.ind); NNF_H.uvCost.map = sr_update_uvMap(NNF_H.uvCost.map, NNF_H.uvCost.data, NNF_H.uvPix.ind); % ========================================================================= % Initialize patch weights % ========================================================================= NNF_H.wPatch = fspecial('gauss', [opt.pSize, opt.pSize], 3); NNF_H.wPatch = NNF_H.wPatch(:); NNF_H.wSumImg = zeros(NNF_H.imgH, NNF_H.imgW, 'single'); indMap = reshape(1:NNF_H.imgH*NNF_H.imgW, NNF_H.imgH, NNF_H.imgW); indPatch = im2col(indMap, [opt.pSize, opt.pSize]); for i = 1: size(indPatch, 2) NNF_H.wSumImg(indPatch(:,i)) = NNF_H.wSumImg(indPatch(:,i)) + NNF_H.wPatch(:); end end function uvPix = sr_get_uvpix(imgSize, prad) % Get uvPix: a field of patch centers for patch-based synthesis % % Input: % - imgSize: [imgHeight, imgWidth] % - prad : radius of a patch, prad = floor(patchSize/2); % Output: % - uvPix : patch center positions 63 % ========================================================================= % Get uvMap uvMap = true(imgSize); uvMap([1:prad, end-prad+1:end], :) = 0; uvMap(:, [1:prad, end-prad+1:end]) = 0; [Y, X] = find(uvMap); % Get uvPix in terms of pos, ind, and mask uvPix.sub = single(cat(2, X(:), Y(:))); uvPix.ind = uint64(sub2ind(imgSize, Y(:), X(:))); uvPix.mask = uvMap; uvPix.numUvPix = size(uvPix.ind, 1); end Ước lượng trường lân cận gần sử dụng thuật toán PatchMatch function NNF = sr_pass(imgTrg, imgSrcPyr, NNF, modelPlane, numIterLvl, opt) % % SR_PASS % % Nearest neighbor field estimation at the current level using the % generalized PatchMatch algorithm % % Input: % - imgTrg: target image % - imgSrcPyr: source image pyramid % - NNF: the current nearest neighbor field % - modelPlane: planar structure model % - numIterLvl: number of iterations at the current level % - opt: parameters % Output: % - NNF: updated nearest neighbor field % ========================================================================= % ========================================================================= % Compute the initial patch cost at the current level % ========================================================================= % Prepare target patch trgPatch = sr_prep_target_patch(imgTrg, opt.pSize); % Prepare source patch [srcPatch, srcPatchScale] = sr_prep_source_patch(imgSrcPyr, NNF.uvTformH.data, opt); % Compute patch matching cost: appearance cost [NNF.uvCost.data, NNF.uvBias.data] = sr_patch_cost_app(trgPatch, srcPatch, opt); % Compute patch matching cost: scale cost 64 if(opt.useScaleCost) costScale = opt.lambdaScale*max(0, opt.scaleThres - srcPatchScale); NNF.uvCost.data = NNF.uvCost.data + costScale; end % Compute patch matching cost: plane compatibility cost if(opt.usePlaneGuide) costPlane = sr_patch_cost_plane(modelPlane.mLogLPlaneProb, NNF.uvPlaneID.data, NNF.uvPix.ind, NNF.uvTformH.data(:,7:8)); NNF.uvCost.data = NNF.uvCost.data + opt.lambdaPlane*costPlane; end % Update cost map NNF.uvCost.map = sr_update_uvMap(NNF.uvCost.map, NNF.uvCost.data, NNF.uvPix.ind); % Initialize visualization if(opt.visFlag) uvTformMap = zeros(NNF.imgH, NNF.imgW, 3, numIterLvl); uvCostMap = zeros(NNF.imgH, NNF.imgW, numIterLvl); uvCostMapInit = NNF.uvCost.map; imgRecSet = zeros(NNF.imgH, NNF.imgW, 3, numIterLvl); end % ========================================================================= % Update the nearest neighbor field using PatchMatch % ========================================================================= for iter = : numIterLvl [NNF, nUpdate] = sr_update_NNF(trgPatch, imgSrcPyr, NNF, modelPlane, opt); avgPatchCost = mean(NNF.uvCost.data); fprintf(' avgPatchCost); %3d\t%12d\t%12d\t%14f\n', iter, nUpdate(1), nUpdate(2), end % Visualization if(opt.visFlag) resPath = 'result/nIter'; if(~exist(resPath, 'dir')) mkdir(resPath); end imgID = opt.imgID; maxCost = max(uvCostMapInit(:)); uvCostMap = uvCostMap/maxCost; uvCostMapInit = uvCostMapInit/maxCost; h2 = figure(2); imshow(uvCostMapInit); colormap jet; uvCostMapC = getframe(h2); imwrite(uvCostMapC.cdata, fullfile(resPath, ['img_', num2str(imgID, '%03d'), '_costMap_iter_00.png'])); 65 % Position map uvPosMap = NNFVis.uvPosMap; imwrite(uvPosMap, fullfile(resPath, ['img_', num2str(imgID, '%03d'), '_uvPosMap.png'])); for iter = 1: numIterLvl % Save uvTformMap imwrite(uvTformMap(:,:,:,iter), fullfile(resPath, ['img_', num2str(imgID, '%03d'),'_tformMap_iter_', num2str(iter, '%02d'), '.png'])); % Save reconstructed image imwrite(imgRecSet(:,:,:,iter), fullfile(resPath, ['img_', num2str(imgID, '%03d'),'_rec_iter_', num2str(iter, '%02d'), '.png'])); % Save matching cost map h2 = figure(2); imshow(uvCostMap(:,:,iter)); colormap jet; uvCostMapC = getframe(h2); imwrite(uvCostMapC.cdata, fullfile(resPath, ['img_', num2str(imgID, '%03d'), '_costMap_iter_', num2str(iter, '%02d'), '.png'])); end end end Tính tốn chi phí xuất function [uvCostApp, uvBias] = sr_patch_cost_app(trgPatch, srcPatch, opt) % SR_PATCH_COST_APP % % Compute appearance-based patch cost: the weighted sum of the absolute difference between between source and target patches % Input: % - trgPatch: target patches - [patchSize*patchSize] x [3] x [numUvPix] % - srcPatch: source patches - [patchSize*patchSize] x [3] x [numUvPix] % - opt: parameters % Output: % - uvCostApp: weighted sum of squared difference - [numUvPix] x [1] % - uvBias: color bias term - [1] x [3] x [numUvPix] % ========================================================================= % ========================================================================= % Apply bias correction % ========================================================================= 66 if(opt.useBiasCorrection) % Mean of source and target patch meanTrgPatch = mean(trgPatch, 1); meanSrcPatch = mean(srcPatch, 1); % Compute bias and clamp it to inteval [opt.minBias, opt.maxBias] uvBias = meanTrgPatch - meanSrcPatch; uvBias = sr_clamp(uvBias, opt.minBias, opt.maxBias); % Apply the bias compensation srcPatch = bsxfun(@plus, srcPatch, uvBias); else uvBias = []; end patchDist = trgPatch - srcPatch; % ========================================================================= % Compute weighted sum of squared distance % ========================================================================= % Sum of absolute distance if(strcmp(opt.costType, 'L1')) patchDist = abs(patchDist); elseif(strcmp(opt.costType, 'L2')) patchDist = patchDist.^2; end % Apply per pixel weight (a Gaussian falloff function) uvCostApp = bsxfun(@times, patchDist, opt.wPatch); uvCostApp = squeeze(sum(sum(uvCostApp, 1),2)); end Tính tốn chi phí mặt phẳng function costPlane = sr_patch_cost_plane(mLogLPlaneProb, uvPlaneIDData, trgPixInd, srcPixSub) % SR_PATCH_COST_PLANE % % Compute planar costs % % Input: % - mLogLPlaneProb: minus log-likelihood of plane assignment % - uvPlaneIDData: plane ID for each target patch % - trgPixInd: target patch index % - srcPixSub: source patch position % Output: % - costPlane: plane compatibility cost % ========================================================================= [imgH, imgW, numPlane] = size(mLogLPlaneProb); 67 % Get the source patch index srcPixSub = round(srcPixSub); srcPixSub(:,1) = sr_clamp(srcPixSub(:,1), 1, imgW); srcPixSub(:,2) = sr_clamp(srcPixSub(:,2), 1, imgH); srcPixInd = sub2ind([imgH, imgW, numPlane], srcPixSub(:,2), srcPixSub(:,1), single(uvPlaneIDData)); % Plane compatibility cost costPlane = mLogLPlaneProb(trgPixInd) + mLogLPlaneProb(srcPixInd); end Ước lượng gần tỷ lệ từ phép biến đổi homography sử dụng khai triển Taylor bậc function uvTformScale = sr_scale_tform(H) % SR_SCALE_TFORM % Estimate the approximated scale from the homography transformation using first-order Taylor expansion % % % h1 h4 h7 h1 - h7*h3 h4 - h7*h6 h7 0 %T = [ h2 h5 h8 ] = [ h2 - h8*h3 h5 - h8*h6 h8 ] * [ ] % h3 h6 h9 0 h3 h6 % T = A*H % Here the scale estimation is the determinant of the matrix A uvTformScale = (H(:,1) - H(:,7).*H(:,3)).* (H(:,5) - H(:,8).*H(:,6)) - (H(:,4) - H(:,7).*H(:,6)).* (H(:,2) - H(:,8).*H(:,3)); uvTformScale = sqrt(abs(uvTformScale)); end Thực lan truyền tìm kiếm ngẫu nhiên vòng lặp % === Nearest neighbor field update === function [NNF, nUpdate]= sr_update_NNF(trgPatch, imgPyr, NNF, modelPlane, opt) % % SR_UPDATE_NNF: % % One iteration of random search and spatial propagation (generalized PatchMatch) for nearest neighbor field estimation % % Input: % - trgPatch: target patches 68 % - imgPyr: source image pyramid % - NNF: the current nearest neighbor field % - modelPlane: planar structure model % - opt: parameters % Output: % - NNF: updated nearest neighbor field % - nUpdate: nUpdate(1) = #updates from propagation % nUpdate(2) = #updates from random sampling % ========================================================================= nUpdate = zeros(1,2); NNF.update.data = false(NNF.uvPix.numUvPix, 1); NNF.update.map = false(NNF.imgH, NNF.imgW); % Random sampling [NNF, n] = sr_random_search(trgPatch, imgPyr, NNF, modelPlane, opt); nUpdate(2) = nUpdate(2) + n; % propagate along four directions for iDirect = 1:4 [NNF, n] = sr_propagate(trgPatch, imgPyr, NNF, modelPlane, opt, iDirect); nUpdate(1) = nUpdate(1) + n; end end % === Random search === function [NNF, nUpdateTotal] = sr_random_search(trgPatch, imgPyr, NNF, modelPlane, opt) % % SC_RANDOM_SEARCH: % % Update the nearest neighbor field using coarse-to-fine random search % % Input: % - trgPatch: target patches % - imgPyr: source image pyramid % - NNF: the current nearest neighbor field % - modelPlane: planar structure model % - opt: parameters % Output: % - NNF: updated nearest neighbor field % - nUpdateTotal:#updates % ========================================================================= imgSize = [NNF.imgH, NNF.imgW]; uvPix = NNF.uvPix; numUvPix = uvPix.numUvPix; searchPosRad = max(imgSize)/4; nUpdateTotal = 0; iter = 1; 69 while(searchPosRad > 1) % Coarse to fine random sampling iter = iter + 1; % ===================================================================== % Draw random sample: srcPos, uvTformA, uvTformH, uvPlaneID % ===================================================================== % Reduce search radius by half searchPosRad = searchPosRad/2; % Retrieve the current source patch position and affine transformation uvTformHCand = sr_uvMat_from_uvMap(NNF.uvTformH.map, uvPix.ind); uvTformACand = sr_uvMat_from_uvMap(NNF.uvTformA.map, uvPix.ind); % Draw random samples of (position: srcPos) and affine deformation (scale, rotation : uvTformD) [srcPosOffset, uvTformD] = sr_draw_rand_sample(searchPosRad, numUvPix, iter, opt); % Apply the position offset srcPos = uvTformHCand(:,7:8) + srcPosOffset; % Apply the affine transformation deformation uvTformACand = sr_apply_affine_tform(uvTformACand, uvTformD); % Draw plane ID candidate if(opt.usePlaneGuide) uvPlaneIDCand = sr_draw_plane_id(NNF.uvPlaneID.planeProbAcc); else uvPlaneIDCand = modelPlane.numPlane*ones(1, uvPix.numUvPix); end % Estimate the domain transformation using the updated source positions % and affine transformation uvTformHCand = sr_src_domain_tform(uvPlaneIDCand, modelPlane, uvTformACand, srcPos, NNF.uvPix.sub); % ===================================================================== % Reject invalid samples % ===================================================================== % Check if the scale of the source patch is valid uvTformHScale = sr_scale_tform(uvTformHCand); uvValidScaleInd = (uvTformHScale >= opt.minScale) & (uvTformHScale opt.errThres; 70 % Valid uv pixels uvValidInd = uvValidPosInd & uvValidScaleInd & uvValidErrInd; uvValidPos = find(uvValidInd); if(size(uvValidPos, 1) ~= 0) % ===================================================================== % Check if the randomly drawed samples reduce the matching cost % ===================================================================== % Prepare valid samples trgPatchCur = trgPatch(:,:,uvValidInd); uvCostDataCur = NNF.uvCost.data(uvValidInd); uvTformHCandCur = uvTformHCand(uvValidInd, :); uvTformACandCur = uvTformACand(uvValidInd, :); uvPlaneIDCandCur = uvPlaneIDCand(uvValidInd); uvPixValid.sub uvPixValid.ind = uvPix.sub(uvValidInd, :); = uvPix.ind(uvValidInd); % Prepare source patches [srcPatch, srcPatchScale] = sr_prep_source_patch(imgPyr, uvTformHCandCur, opt); % Compute patch matching cost: appearance cost [costPatchCand, uvBiasCand] = sr_patch_cost_app(trgPatchCur, srcPatch, opt); % Compute patch matching cost: scale cost if(opt.useScaleCost) costScale = opt.lambdaScale*max(0, opt.scaleThres srcPatchScale); costPatchCand = costPatchCand + costScale; end % Compute patch matching cost: plane compatibility cost if(opt.usePlaneGuide) costPlane = sr_patch_cost_plane(modelPlane.mLogLPlaneProb, uvPlaneIDCandCur, uvPixValid.ind, srcPos(uvValidInd,:)); costPatchCand = costPatchCand + opt.lambdaPlane*costPlane; end % Check which one to update updateInd = (costPatchCand < uvCostDataCur); % ===================================================================== % Update the nearest neighbor field % ===================================================================== nUpdate = sum(updateInd); if(nUpdate~=0) uvUpdatePos = uvValidPos(updateInd); % === Update NNF data === NNF.uvTformH.data(uvUpdatePos, :) = uvTformHCandCur(updateInd, :); 71 NNF.uvTformA.data(uvUpdatePos, :) = uvTformACandCur(updateInd, :); NNF.uvPlaneID.data(uvUpdatePos) = uvPlaneIDCandCur(updateInd); NNF.uvCost.data(uvUpdatePos) = costPatchCand(updateInd); if(opt.useBiasCorrection) uvBiasCand = uvBiasCand(:, :, updateInd); NNF.uvBias.data(:,:,uvUpdatePos) = uvBiasCand; end NNF.update.data(uvUpdatePos) = 1; % === Update NNF map === uvPixValidInd = uvPixValid.ind(updateInd); NNF.uvTformH.map = sr_update_uvMap(NNF.uvTformH.map, uvTformHCandCur(updateInd,:), uvPixValidInd); NNF.uvTformA.map = sr_update_uvMap(NNF.uvTformA.map, uvTformACandCur(updateInd,:), uvPixValidInd); NNF.uvPlaneID.map = sr_update_uvMap(NNF.uvPlaneID.map, uvPlaneIDCandCur(updateInd), uvPixValidInd); NNF.uvCost.map = sr_update_uvMap(NNF.uvCost.map, costPatchCand(updateInd), uvPixValidInd); if(opt.useBiasCorrection) uvBiasCand = squeeze(uvBiasCand)'; NNF.uvBias.map = sr_update_uvMap(NNF.uvBias.map, uvBiasCand, uvPixValidInd); end NNF.update.map = sr_update_uvMap(NNF.update.map, 1, uvPixValidInd); nUpdateTotal = nUpdateTotal + nUpdate; end end end end function uvTformACand = sr_apply_affine_tform(uvTformA, uvTformD) uvTformACand = zeros(size(uvTformA), 'single'); uvTformACand(:, 1:2) = bsxfun(@times, uvTformD(:,1:2), uvTformA(:,1)) + bsxfun(@times, uvTformD(:,3:4), uvTformA(:,2)); uvTformACand(:, 3:4) = bsxfun(@times, uvTformD(:,1:2), uvTformA(:,3)) + bsxfun(@times, uvTformD(:,3:4), uvTformA(:,4)); end function validPosInd = sr_check_valid_pos(pos, imgSize, prad) imgH = imgSize(1); imgW = imgSize(2); validPosInd = (pos(:,1) = prad + 1) & (pos(:,2) >= prad + ) & (pos(:,2) opt.errThres; % The valid patch indices to start with uvValidInd = uvPixN.validInd & NNF.update.map(uvPixN.ind) & uvValidCostInd; numUpdatePix = sum(uvValidInd); while(numUpdatePix ~= 0) numUpdatePix = 0; % exit the loop if there are no valid candidates % ===================================================================== % Propare candidate patch transformation % ===================================================================== % Prepare uvPix, uvPixNCur uvPix.sub = NNF.uvPix.sub(uvValidInd, :); uvPix.ind = NNF.uvPix.ind(uvValidInd); uvPixNCur.sub = uvPixN.sub(uvValidInd, :); uvPix uvPixNCur.ind = uvPixN.ind(uvValidInd); trgPatchCur srcPosCur % neighbor of = trgPatch(:,:, uvValidInd); % target patch = NNF.uvTformH.data(uvValidInd, 7:8); % source patch pos uvCostCur matching cost uvPlaneIDCur ID = NNF.uvCost.data(uvValidInd); % current patch = NNF.uvPlaneID.map(uvPixNCur.ind); % current plane uvValidPos positions = find(uvValidInd); % Valid pixel % Get candidate uvTform candidates uvTformACand = sr_uvMat_from_uvMap(NNF.uvTformA.map, uvPixNCur.ind); uvTformHCand = sr_uvMat_from_uvMap(NNF.uvTformH.map, uvPixNCur.ind); srcPos = uvTformHCand(:,7:8); % Generate candidate transformation by propagation uvTformHCand = sr_trans_tform(uvTformHCand, opt.propDir(indDirection,:)); 74 % ===================================================================== % Reject invalid samples % ===================================================================== % Check if the nearest neighbors are valid source patches uvValidSrcInd = sr_check_valid_pos(srcPos, [NNF.imgH, NNF.imgW], opt.pRad); % Check if the nearest neighbors are already the same as the existing one diff = abs(srcPos - srcPosCur); uvValidDistInd = ((diff(:,1) > ) | (diff(:,2) > )); % Check if the errors are already below a threshold uvValidErrInd = uvCostCur > opt.errThres; % Valid pixel indices uvValidInd = uvValidSrcInd & uvValidDistInd & uvValidErrInd; numUvValid = sum(uvValidInd); if(numUvValid ~= 0) % ===================================================================== % Check if the propagated samples reduce the matching cost % ===================================================================== trgPatchCur = trgPatchCur(:,:, uvValidInd); uvCostCur = uvCostCur(uvValidInd); uvTformHCand = uvTformHCand(uvValidInd, :); uvTformACand = uvTformACand(uvValidInd, :); uvPlaneIDCand = uvPlaneIDCur(uvValidInd); uvValidPos uvPixValid.sub uvPixValid.ind = uvValidPos(uvValidInd); = uvPix.sub(uvValidInd,:); = uvPix.ind(uvValidInd); % Grab source patches [srcPatch, srcPatchScale] = sr_prep_source_patch(imgPyr, uvTformHCand, opt); % Compute patch matching cost: appearance cost [costPatchCand, uvBiasCand] = sr_patch_cost_app(trgPatchCur, srcPatch, opt); % Compute patch matching cost: scale cost if(opt.useScaleCost) costScale = opt.lambdaScale*max(0, opt.scaleThres srcPatchScale); costPatchCand = costPatchCand + costScale; end % Compute patch matching cost: planar compatibiltiy cost if(opt.usePlaneGuide) costPlane = sr_patch_cost_plane(modelPlane.mLogLPlaneProb, uvPlaneIDCand, uvPixValid.ind, srcPosCur(uvValidInd, :)); costPatchCand = costPatchCand + opt.lambdaPlane*costPlane; end 75 % Check which one to update updateInd = costPatchCand < uvCostCur; % ===================================================================== % Update the nearest neighbor field % ===================================================================== nUpdate = sum(updateInd); if(nUpdate ~= 0) uvUpdatePos = uvValidPos(updateInd); % === Update NNF data === NNF.uvTformH.data(uvUpdatePos, :) = uvTformHCand(updateInd,:); NNF.uvTformA.data(uvUpdatePos, :) = uvTformACand(updateInd,:); NNF.uvPlaneID.data(uvUpdatePos) = uvPlaneIDCand(updateInd); NNF.uvCost.data(uvUpdatePos) = costPatchCand(updateInd); % Apply bias correction if(opt.useBiasCorrection) uvBiasCand = uvBiasCand(:,:,updateInd); NNF.uvBias.data(:,:,uvUpdatePos) = uvBiasCand; end NNF.update.data(uvUpdatePos) = 1; % updateInd; % === Update NNF map === uvPixValidInd = uvPixValid.ind(updateInd); NNF.uvTformH.map = sr_update_uvMap(NNF.uvTformH.map, uvTformHCand(updateInd,:), uvPixValidInd); NNF.uvTformA.map = sr_update_uvMap(NNF.uvTformA.map, uvTformACand(updateInd,:), uvPixValidInd); NNF.uvPlaneID.map = sr_update_uvMap(NNF.uvPlaneID.map, uvPlaneIDCand(updateInd), uvPixValidInd); NNF.uvCost.map = sr_update_uvMap(NNF.uvCost.map, costPatchCand(updateInd), uvPixValidInd); if(opt.useBiasCorrection) uvBiasCand = squeeze(uvBiasCand)'; NNF.uvBias.map = sr_update_uvMap(NNF.uvBias.map, uvBiasCand, uvPixValidInd); end NNF.update.map = sr_update_uvMap(NNF.update.map, 1, uvPixValidInd); % === Update uvValidInd === uvPixNextSub = uvPixValid.sub(updateInd,:); uvPixNextSub = bsxfun(@plus, uvPixNextSub, opt.propDir(indDirection,:)); uvPixNextInd = sub2ind([NNF.imgH, NNF.imgW], uvPixNextSub(:,2), uvPixNextSub(:,1)); updateMap = NNF.uvPix.mask; updateMap(uvPixNextInd) = 0; uvValidInd = ~updateMap(NNF.uvPix.ind); 76 uvValidInd = uvValidInd & uvPixN.validInd; nUpdateTotal = nUpdateTotal + nUpdate; numUpdatePix = sum(uvValidInd); end end end end 77 ... SIÊU PHÂN GIẢI ẢNH SỐ 1.1 Ảnh số 1.1.1 Khái niệm ảnh số 1.1.2 Độ phân giải ảnh số .8 1.2 Siêu phân giải ảnh số 1.3 Một số phương pháp siêu phân giải ảnh. .. nhị phân điểm ảnh lưu trữ máy tính thường nén 1.1.2 Độ phân giải ảnh số Khi lấy mẫu ảnh, ta thu nhiều điểm ảnh ảnh chi tiết Mật độ điểm ảnh ảnh gọi độ phân giải ảnh Độ phân giải cao ảnh thể rõ chi... tài ? ?Nghiên cứu phát triển phương pháp nâng cao độ phân giải ảnh số? ?? hoàn thành Trong luận văn đề cập đến vấn đề quan tâm lĩnh vực xử lý ảnh, vấn đề siêu phân giải ảnh số Luận văn nghiên cứu, giải

Ngày đăng: 12/02/2021, 17:57

Mục lục

    CHƯƠNG 1 - TỔNG QUAN VỀ SIÊU PHÂN GIẢI ẢNH SỐ

    CHƯƠNG 2 – THUẬT TOÁN SIÊU PHÂN GIẢI DỰA TRÊN CÁC MẪU TỰ THÂN BIẾN ĐỔI

    CHƯƠNG 3 – CÀI ĐẶT, THỬ NGHIỆM VÀ ĐÁNH GIÁ THUẬT TOÁN SIÊU PHÂN GIẢI DỰA TRÊN CÁC MẪU TỰ THÂN BIẾN ĐỔI

    TÀI LIỆU THAM KHẢO

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan