Pixel values different for binary (logical array) image using impixel() vs accessing logical matrix normally

조회 수: 3 (최근 30일)
I don't understand why when trying to access the pixel values of this image i get different values using impixel() vs accessing the matrix of the bianrized and thinned image which is a logical matrix. The impixel() values are the correct ones while the normal matrix accessing gives me the wrong values different from both the impixel() method and viewing the imagematrix in the matlab workspace. I cannot use impixel() in my code because it slows down the code considerably, can anyone give me a workaround to get the correct pixel values without using impixel(). By the way i used imbinarize() for binarization and bwmorph() for thinning with the method set to thin.
This is the thinned image and this is the code
thinImg(372:374, 207:209)
impixel(thinImg, 372:374, 207:209)
Assuming the image is called thinImg. Please help, I have tried everything and reserched everywhere but no results.
Thanks.

채택된 답변

Image Analyst
Image Analyst 2020년 2월 25일
If you look up the documentation for impixel(), you'll see that it want coordinates in x,y format (i.e. column, row), NOT row, column like normal image and matrix indexing wants. Swap your coordinates and they should match.
  댓글 수: 4
Image Analyst
Image Analyst 2020년 2월 25일
It's a common beginner mistake. You will have to keep an eye out from now on because some of the functions do things with (x,y) format while other functions, and matrices, do things with (row, column) format, which is the reverse. You just never know. Even I have to go back and check for things like bwboundaries() - does it return in (x,y) or (row, column) form?
Nick Spiker
Nick Spiker 2021년 9월 21일
I guess it's too late now for the math community to fix it but I always thought y axis was up/down and x axis is left right. Too bad matrix indexing is backwards.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by