Different output for same code in two different computers

Hello,
I am using the following MATLAB code:
a=im2uint8(a);
agray=im2gray(a);
figure;tiledlayout('flow','Padding','tight','TileSpacing','tight')
aadjust=imadjust(imsharpen(agray,'Radius',10,'Amount',2));
nexttile;imshow(aadjust); axis on; title("Adjusted Image")
[Rows Columns] = size(aadjust);
bwout = imbinarize(aadjust);
bwout(1:40,:)= 0;
tempend=find(agray(:,floor(Columns/2))==0);
tempend(tempend<floor(Rows/2))=[];
tempend=min(tempend);
bwout(tempend-20:Rows,:)= 0;
bwout=bwareaopen(bwout,10000);
nexttile;imshow(bwout);axis on; title("Image binarized")
where "a" is an input image I provide to MATLAB. The problem is that I am using the exact same code in another computer with the exact same image but I am getting a slightly different output image "bwout", and both computers are using MATALAB R2022b with Windows.
Is there any explanation for why is this happenning?
I attach the two images I'm getting in both computers, you'll notice slight differences in some pixels. After further processing those small differences become a huge difference so I need to have the same output in both computers. Any idea why is this happenning??
Image A

7 commentaires

Please attach the original image for testing.
Question: does one of the systems happen to be AMD based, and the other system happens to be Intel based?
Galo
Galo le 24 Avr 2023
Modifié(e) : Galo le 24 Avr 2023
Both computer's processors are Intel.
Attached is the original image used for the exmaple.
You'll need to zoom in to an area close to "xlim([220 320])" in order to see the same area in the examples I provided.
Which area are you zooming in on? Is it where the handle (?) meets the body on the left, near y = 750 x = 200?
a = imread('image_a.png');
a=im2uint8(a);
agray=im2gray(a);
figure;tiledlayout('flow','Padding','tight','TileSpacing','tight')
aadjust=imadjust(imsharpen(agray,'Radius',10,'Amount',2));
nexttile;imshow(aadjust); axis on; title("Adjusted Image")
[Rows Columns] = size(aadjust);
bwout = imbinarize(aadjust);
bwout(1:40,:)= 0;
tempend=find(agray(:,floor(Columns/2))==0);
tempend(tempend<floor(Rows/2))=[];
tempend=min(tempend);
bwout(tempend-20:Rows,:)= 0;
bwout=bwareaopen(bwout,10000);
nexttile;imshow(bwout);axis on; title("Image binarized")
xlim([220 320])
Yes, exactly, somewhere close to this area:
xlim([220 320])
ylim([720 795])
And you should be able to see something similiar to my first two images.
Differences in GPU and/or graphics drivers and monitor resolution can all be factors.
DGM
DGM le 25 Avr 2023
Modifié(e) : DGM le 25 Avr 2023
It's not clear where the difference is initially occurring, so I'm focusing on the observable difference and working backwards:
% this is the image returned from imsharpen()
imwrite(asharp(720:790,220:320),'asharp.png')
% this is the image returned from imadjust()
imwrite(aadjust(720:790,220:320),'aadjust.png')
% this is the image returned from imbinarize() prior to any edits
imwrite(bwout0(720:790,220:320),'bwout0.png')
% this is the final binary image after the call to bwareaopen()
imwrite(bwout(720:790,220:320),'bwout.png')
The resulting images are attached.
FWIW, I'm using R2019b, Linux, AMD. My results are apparently the same as your second image.
I'm not saying there definitely is no bug, but different computers do give different answers, this is just the way floating point computations work. If your processors have different numbers of cores or different vector processing architectures then the way they parallelize your code will lead to order-of-computation related differences (or sometimes completely different algorithms will be used). This can be especially noticeable in image processing code where a mask is being computed based on a threshold.
You might get your two MATLABs to behave the same by calling maxNumCompThreads(1) on both before running your code.

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 24 Avr 2023

Commenté :

le 25 Avr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by