5 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

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

Image Analyst
on 13 Dec 2019

Instead of

NormDelta = 255*(DiffoverA -abs(MinValue))/(MaxValue + abs(MinValue));

try using mat2gray(), rescale(), or imadjust(). And I would use imshow() with [] rather than image() or imagesc(). If the image still looks uniform, I'd examine the image in the workspace variable editor or look at its histogram. Maybe it really is largely the same value except for a very few pixels that are ruining the normalization.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.