Я пытаюсь преобразовать некоторый код MATLAB в Python, связанный с обработкой изображений.
Когда я сделал
% matlab R2017a
nhood = true(5); % will give 5x5 matrix containing 1s size 5x5
J = imclose(Image,nhood);
в MATLAB, результат отличается от того, когда я did
import cv2 as cv
kernel = np.ones((5,5),np.uint8) # will give result like true(5)
J = cv.morphologyEx(Image,cv.MORPH_CLOSE,kernel)
in Python.
Это результат MATLAB:

And this is for the Python:

The difference is 210 pixels, see below. The red circle shows the pixels that exist in Python with 1 value but not in the MATLAB.

Sorry if it’s so small, my image size is 2048x2048 and have values 0 and 1, and the error just 210 pixels.
When I use another library such as skimage.morphology.closing
and mahotas.close
with the same parameter, it will give me the same result as MORPH.CLOSE
.
What I want to ask is:
- Am I using the wrong parameter in Python like the
kernel = np.ones((5,5),np.uint8)
?
- If not, is there any library that will give me the same exact result like
imclose()
MATLAB?
- Which of the MATLAB and Python results is correct?
I already looked at this Q&A . Когда я использую borderValue = 0
в MORPH.CLOSE
, мой результат даст мне ошибку 2115 пикселей, которые содержат 1 значение в MATLAB, но не в Python.
[UPDATE]
входное изображение Входное изображение
обрезанное разностное изображение обрезанное разностное изображение
Итак, для изображения разностных пикселей оказывается, что пиксели не только находятся в этой позиции, но и разбросаны по нескольким позициям. Вы можете увидеть это здесь 
And if seen from the results, the location of the pixel error coincides at the ends of the row or column of the matrix.
I hope it can make more hints for this question.
- Это программа в MATLAB, которую я использую для проверки ошибки,
mask = zeros(2048,2048); %inisialisasi error matrix
error = 0;
for x = 1:size(J_Matlab,1)
for y = 1:size(J_Matlab,2)
if J_Matlab(x,y)== J_Python(x,y)
mask(x,y) = 0; % no differences
else
mask(x,y) = 1;
error = error + 1;
end
end
end
, поэтому я загружаю данные Python в MATLAB , затем я сравниваю его с данными MATLAB. И если вы хотите проверить данные, которые я использую для ввода в функции закрытия, вы можете посмотреть их в разделе комментариев (в ссылке на диск)
поэтому для этой проблемы мой учитель сказал, что можно использовать программу MATLAB или Python, потому что ошибка несущественна. но если я найду решение, я опубликую его здесь как можно скорее. Спасибо за инструкции, предложения и критику за мой первый пост.