Image processing loop after loop

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);

 Accepted Answer

Walter Roberson
Walter Roberson on 17 Jan 2018
Edited: Walter Roberson on 17 Jan 2018
ImageBasic = imread('rentgen.jpg');
Imagemy = imresize(ImageBasic,[40 40]);
Imagemy2 = rgb2gray(Imagemy);
imshow(Imagemy2)

4 Comments

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 on 17 Jan 2018
Edited: Walter Roberson on 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.
You've marked it as solved, so I assume it's solved. If not, post 'rentgen.jpg' so we can try it.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!