将灰度图像幅度标准化为一

时间:2016-09-13 19:23:52

标签: matlab image-processing fft

我想在MATLAB上将灰度图像的幅度标准化为1(reference

幻灯片18显示了结果应该是什么样子,但出于某种原因,当我运行我的代码时,我得到一个完整的黑色图像输出,这是我的代码:

 % Load images
 f1 = (imread('f1.jpg'));
 f2 = (imread('f2.jpg'));

 %compute 2D FT of F1 and F2

 F1 = fft2(double(f1));
 F2 = fft2(double(f2));

 % Find magnitude and phase of the two images

 F1Mag = abs(F1);
 F1Phase = angle(F1);

 F2Mag = abs(F2);
 F2Phase = angle(F2);

 % set magnitudes to 1

 Gone = exp(1j*F1Phase);
 Gtwo = exp(1j*F2Phase);

 %invert to image

 gone = uint8(ifft2(Gone));
 gtwo = uint8(ifft2(Gtwo));

我不确定我做错了什么,任何帮助/建议都会令人惊讶。谢谢

1 个答案:

答案 0 :(得分:2)

您正在将数据(由负数和数字<1组成)投射到companyRequests.addValueEventListener(new ValueEventListener() { public void onDataChange(DataSnapshot dataSnapshot) { // at the start we need to still load all children final long[] pendingLoadCount = { dataSnapshot.getChildrenCount() }; for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) { //For each key I retrieve its details from the requests node DatabaseReference currRequest = rootNode.child("requests/" + childSnapshot.getKey()); currRequest.addListenerForSingleValueEvent(new ValueEventListener() { public void onDataChange(DataSnapshot dataSnapshot) { String time; time = (String) dataSnapshot.child("time").getValue(); Request request = new Request(time); allRequests.add(request); // we loaded a child, check if we're done pendingLoadCount[0] = pendingLoadCount[0] - 1; if (pendingLoadCount[0] == 0) { RequestAdapter adapter = new RequestAdapter(RequestsListActivity.this, allRequests); rListView.setAdapter(adapter); } } ...onCancelled... }); } } }); ,这有效地导致您将所有值设置为uint8,从而导致黑色图片。您希望将图像保留为0并使用double来显示结果。

imagesc

enter image description here

如果您确实希望输出为f1 = imread('cameraman.tif'); F1 = fft2(f1); % Set the magnitude to 1 G1 = exp(1j * angle(F1)); % Convert back to image domain and take the real component g1 = real(ifft2(G1)); % Display the result using imagesc so it's scaled imagesc(g1); colormap gray; ,则需要先使用uint8对图像进行规范化,然后再按mat2gray 进行缩放将其转换为255

uint8