Images don't show properly with imshow after certain calculation

11 views (last 30 days)
Hello all,
The question is I need to calculate the matrix of a uint8 image. After the calculation (one order difference of the field) and normalization, I tried to figure out the image with imshow, however, the reults is a white blank or no longer smooth. The figure1.jpg can be any picture as you can find.
I should clarify that the values are uint8 after imread and I used "im2double" to transfer the type to double. The final imshow image is black and the final image will looks like some discrete dots when the matrix times 255.
clear all
deltax = 1;
deltay = 1;
AmpDistribution = imread('figure1.jpg')
AmpDistributionDouble = im2double(AmpDistribution);
AmpDistributionDouble(isnan(AmpDistributionDouble))=0;
[MSize, NSize, VSize] = size(AmpDistributionDouble);
DiffoverA = zeros(MSize,NSize,VSize);
for i = 2: MSize-1
for j = 2:NSize-1
for k = 1:VSize
DiffoverA(i,j,k) = (( AmpDistributionDouble(i+1,j,k) -AmpDistributionDouble(i,j,k))./(deltax) + (AmpDistributionDouble(i,j+1,k) -AmpDistributionDouble(i,j,k))./(deltay^2 ));
end
end
end
DiffoverA(isnan(DiffoverA))=0;
DiffoverA(DiffoverA==inf)=0;
MinValue = min(DiffoverA,[],'all');
MaxValue = max(DiffoverA,[],'all');
NormDelta = 255*(DiffoverA -abs(MinValue))/(MaxValue + abs(MinValue));
figure(1)
image(AmpDistribution);
figure(2)
imshow(AmpDistributionDouble,[]);
figure(3)
imshow(NormDelta,[]);
shading interp

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 10 Dec 2019
When you do things like this the errors are always (in my experience) in different normalizations and type-castings. To work these out I always go to the stage of looking at the individual R/G/B-planes of my images and check where they lie in intensity. Typically something like this:
subplot(2,2,1)
imagesc(NormDelta(:,:,1)),colorbar
subplot(2,2,2)
imagesc(NormDelta(:,:,2)),colorbar
subplot(2,2,3)
imagesc(NormDelta(:,:,3)),colorbar
subplot(2,2,4)
manualScale = @(I) (I-min(I(:)))/(max(I(:))-min(I(:)));
imagesc(manualScale(NormDelta))
Then you'll see where your normalised NormDelta are in intensity.
Finally: Your normalization step looks "very peculiar" to me, but I cant say if that is what you want.
HTH
  14 Comments
Walker
Walker on 16 Dec 2019
@Image Analyst Thank you so much for your reply. imshow works well as you said. Yes, I'll try with other command. Until now, the results is basically resonable.@Bjorn Gustavsson @Image Analyst Thank you both very much.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!