Read .png image and perform commands (example given)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ilyass Boukhari
am 17 Dez. 2020
Kommentiert: Image Analyst
am 17 Dez. 2020
Hello,
I have been given a list of commands from my teacher for a matlab .png image, and I am trying to replicate the same with an image of my choice (same .png).
With the image of my choice Matlab won't read it as comes up with some errors.
Below the working command+image I have been given. File name: ReadTiffImageDataExample_01.png
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/463975/image.png)
%%
% Example 2:
% Read in a .png image into MATLAB, and display it:
t = Tiff('peppers_RGB_tiled.tif','r');
imageData = read(t);
% Display the image.
figure(2)
imshow(imageData);
title('Peppers Image (RGB)')
%% % Example 3:
% Display Just Y component of an image that has been read into MATLAB:
t = Tiff('peppers_YCbCr_tiled.tif','r');
[Y,Cb,Cr] = read(t);
%Display the Y component of the image:
figure(3)
imshow(Y);
title('Peppers Image (Y Component)');
%%
% Example 4:
% In a 2D image, find the locations of all pixels whose value is above a
% chosen threshold:
% Fist, set all pixels of Y-component of image that are below a certain Threshold to
% zero:
% First choose threshold (example 200; could relate to a threshold
% temperature if this were a temperature-scaled image from a thermal camera, for exmaple)
Threshold = 150;
% Load Y-component of image data into a matrix, ready to be threshold checked:
Thresholded_Matrix = Y;
% Set all pixel values less than Threshold to zero:
Thresholded_Matrix(Thresholded_Matrix<Threshold)=0;
% Display Thresholded_Matrix:
figure(4)
imshow(Thresholded_Matrix);
% Find the indices (matrix row and column numbers) of locations where the
% pixel value of the Y-component image data is greater than Threshold;
%(these would correspond to x,y coordinates of places on the image where
% pixel value is above the threshold, and hence, if this where a temperature-scaled thermal
% camera image, for example, would be the 2D spatial coordinates
% (assuming 2D plan-view image capture from above)of places
% in the image that are above the temperature threshold):
% Display as row and column coordinates in the command window:
linearIndexes = find(Y>Threshold);
[rows, columns] = ind2sub(size(Y), linearIndexes)
% Also plot the Thresholded Matrix as a sruface:
figure(5)
surf(Thresholded_Matrix);
Below the result of what I really need, part of "Example 4" (but I believe that pieces of code in the previous examples might be needed for this)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/463980/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/463985/image.png)
Now, this is my image which matlab doesn't read, therefore cannot perform the commands above. File name: flir.png
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/463990/image.png)
load('flir.png');
a = Tiff('flir_YCbCr_tiled.tif','r');
[Y,Cb,Cr] = read(a);
>> fire1
Error using Tiff (line 651)
Could not open file 'flir_YCbCr_tiled.tif'.
Error in fire1 (line 3)
a = Tiff('flir_YCbCr_tiled.tif','r');
How can I perform the same commands with my image? Am I starting with the right commands?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 17 Dez. 2020
You don't have a file called 'flir_YCbCr_tiled.tif' on your search path. So just replace load(), a=, and this:
t = Tiff('peppers_RGB_tiled.tif','r');
imageData = read(t);
with this
fileName = 'flir.png';
imageData = imread(fileName);
4 Kommentare
Image Analyst
am 17 Dez. 2020
Read in whatever image you want/need to read in. If you want the flir image, read that in instead of the peppers image:
rgbImage = imread('flir.png');
ycbcrImage = rgb2ycbcr(rgbImage);
[Y,Cb,Cr] = imsplit(ycbcrImage);
imshow(Y, []);
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!