Some .jpeg photos can not be processed by Matlab code.
33 ビュー (過去 30 日間)
古いコメントを表示
The program test is taken, with minor modifications, from a larger program I have written for image analysis. This larger program has worked well when some .jpg images are input. However, when the attached .jpg image is input, it fails completely. I have traced the problem to the inability of the test after the if statement to work correclty. The test_array shows the values of red, green and blue intensity are about 160 to 200 each so their sum must be about 480 to 600. However, even though the sum of the intensities of the colours of the pixels is greater than 300, 400, or usually, 500, the red colour of the Inclusion Darkness titled images shows the pixel somehow passes the if test. I have no idea how pixels this bright could pass such a test.
0 件のコメント
回答 (2 件)
John D'Errico
2024 年 10 月 11 日 1:49
編集済み: John D'Errico
2024 年 10 月 11 日 1:55
I've not even looked at your code. But you have jpg images, uint8 code values. So I wonder if adding the code values caused an overflow.
x = uint8([200 200])
x(1) + x(2)
And now that I looked at your code, that is exactly what you did.
The images where it works are those that do not overflow the 255 boundary of uint8.
xsum = sum(x)
whos xsum
I would note that had you used sum, it would have solved your problem, converting to a double on the fly.
So you CAN process those images. But you needed to write code that is robust to what can happen.
DGM
2024 年 10 月 11 日 1:58
編集済み: DGM
2024 年 10 月 11 日 2:31
The sum of the elements will always be <=255. You're adding uint8 values, so they'll be truncated.
% inputs
inclusion_darkness = 500;
inpict = imread("Wabi_P2-1_100X.jpg");
% create a mask
mask = sum(inpict,3) <= inclusion_darkness;
imshow(mask)
% if you want to do an overlay for visualization
% that's fine, but i don't think it's nearly as readable
% and the mask is what's used for processing anyway
outpict = imoverlay(inpict,mask,[1 0 0]);
imshow(outpict)
% if you want, save the image with imwrite
% instead of using a screenshot
% don't use JPG for anything of technical purpose
imwrite(outpict,'op.png')
I don't know that using the sum of channels is a great way to segment this image, and I would expect that you'd be doing something to flatten the background (imflatfield(), imtophat(), imbothat())
Something like:
% inputs
inclusion_darkness = 0.75; % unit-scale
inpict = imread("Wabi_P2-1_100X.jpg");
% strip color
inpict = im2gray(inpict);
% flatten and normalize the image
% there are other ways to do this
% normalization might not always be desirable
se = strel('disk',10);
B = imbothat(inpict,se);
inpict = 1-mat2gray(B); % this is now in unit-scale
imshow(inpict)
% create a mask
% this is the only part that we really need
mask = inpict <= inclusion_darkness;
imshow(mask)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!