first post ever, and im kinda desperate ...
So there is my code, and i know i can do it by a simple function. But its not the point of the task i have ;(
And my question is how to show an image here correctly. cause disp(array) works perfectly, it shows whole array in matlab window with values from 1 to 255, lovely. But when i want to show it as an image (with imshow after mat2gray) its either black for Imagemy2(n,k)=0; or white for anything else i want to put there. Thank you for your help :)
ImageBasic = imread('rentgen.jpg');
Imagemy = imresize(ImageBasic,[40 40]);
array = zeros(40,40);
Imagemy2= mat2gray(array);
K = 40;
N = 40;
for k=1:K
for n=1:N
Imagemy2(k,n)=Imagemy(k,n);
end
end
disp(Imagemy2);
figure(2);
subplot(121)
imshow(Imagemy);
subplot(122)
imshow(Imagemy2);

 Réponse acceptée

Walter Roberson
Walter Roberson le 17 Jan 2018
Modifié(e) : Walter Roberson le 17 Jan 2018

0 votes

ImageBasic = imread('rentgen.jpg');
Imagemy = imresize(ImageBasic,[40 40]);
Imagemy2 = rgb2gray(Imagemy);
imshow(Imagemy2)

4 commentaires

Damian Pietron
Damian Pietron le 17 Jan 2018
will try in a minute, i made everything by premade functions ( mix max filters, median filter, different masks aka 2x2 3x3 4x4, negatives ) and named one of the sections ' hall of shame ' on my paper for labs
and if this will make my problem disapear ill feel dumb
Damian Pietron
Damian Pietron le 17 Jan 2018
Modifié(e) : Walter Roberson le 17 Jan 2018
no, wait, not the problem, image is in grey scale cause its pantomogram ( an x-ray CT)
so the rgb2gray changes nothing
In the several decades since JPEG was released, I have only seen one legitimate grey-scale JPEG image "in the wild" (that is, outside of test images produced just to prove that it could be done.) JPEG images are almost always RGB images even when they are representing gray tones.
That said, you might want to apply mat2gray() after you do the rgb2gray(). You can test ahead of time whether that is necessary by using the above code and changing
imshow(Imagemy2)
to
imshow(Imagemy2, [])
If your desired image shows up, then you should probably insert the mat2gray() call.
Image Analyst
Image Analyst le 17 Jan 2018
You've marked it as solved, so I assume it's solved. If not, post 'rentgen.jpg' so we can try it.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by