imhist image pixel intensity uint8
이전 댓글 표시
Background/purpose: I am interested in using the Otsu method to threshold grayscale images. I am attempting to replicate the outsuthresh example found on Mathworks ( https://www.mathworks.com/help/images/ref/otsuthresh.html )
I downloaded the standard 8-bit "coins.png" image, and I loaded this image into my Workspace using imread.

Problem: After loading the coins.png image (uint 8) and a different image (uint16), the imhist function of the 8-bit image outputs image counts are in a single bin. I can't figure out how to interchangeable use imhist with 8-bit and 16-bit images.
I discovered that I can get the 'uint88" or "uint16" descriptor for the respective variables only if I imread directly from my Current Folder. Surely there is a way to use external paths to load images and define the pixel resolution.
댓글 수: 4
If you're trying to download the file from somewhere else via imread() or something, then you're probably not getting the file you think you're getting. You might not even be working with an image at all. In order to know, we'd have to see an example of the code you're using to read the files.
That said, the coins.png image is included in the IPT imdata directory, so it's already on the path:
A = imread('coins.png');
class(A)
imhist(A)
imshow(A)
J Toole
2023년 2월 27일
For the purpose of reading the file, casting to double is not necessary; however, you need to be aware that you're then working with integer-class (uint8) data. Most all of the image processing tools know how to handle that just fine, but there are certain restrictions on what you can do with integer-class arrays without extra effort or precaution.
You would have to deal with the hazards of truncation and rounding when directly performing mathematical operations on them, and you're restricted on performing certain arithmetic between integer-class and float-class arrays. Whether any of that would be an issue in your case, I don't know. For imhist(), imbinarize(), it wouldn't be.
If you find that you do need to convert images to floating-point for some tasks, be aware that most tools that are scale-dependent will expect floating-point images to be unit-scale (0-1). When you use double() on a uint8 image, the values are not rescaled; while that may be a convenience in some cases, something like imshow() or imwrite() won't know what to do with it. When you use im2double(), the array is cast and rescaled. You can choose to design your workflow either way, but I recommend sticking with the canonical scaling (i.e. using im2double() instead of double()) unless you're familiar with how your tools will treat an image that's improperly-scaled for its class.
J Toole
2023년 2월 27일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

