make a picture from excel file with MATLAB

hi all, i have excel file which in it, there is a shape of something that specify with numbers, i want to write a code in matlab that make a picture or plot of it , that in it all the cells with same values have a color that i choose, i.e in the picture below , matlab make a picture of a Rectangular, that all cells with value of "nan" be white, and all cells with a value of "20" be red an so on.
thanks so much.

 채택된 답변

Joseph Cheng
Joseph Cheng 2015년 3월 2일
편집: Joseph Cheng 2015년 3월 2일

0 개 추천

I would start by using the function xlsread() to read in the specified excel file and the range of where the image is create. Then using the == comparison you can then create the different color layers. example:
[num txt raw] = xlsread(____,____)
raw = cell2mat(raw);
Img(:,:,1) = 20==raw | isnan(raw);
Img(:,:,2) = 30==raw | isnan(raw);
Img(:,:,3) = 40==raw | isnan(raw);

댓글 수: 6

baran
baran 2015년 3월 2일
thanks, is there any way to specify arbitrary color for each value, i mean all 20 be blue and so on. is the Img(:,:,1) mean specific color?
i run this code, but there is something wrong . the error is :
Undefined function 'eq' for input arguments of type 'cell'.
Error in test (line 2)
Img(:,:,1) = {20}==raw | isnan(cell2mat(raw));
what i shoud do ?
Joseph Cheng
Joseph Cheng 2015년 3월 2일
images are broken into 3 different color layers (RGB). combinations of values between 0 and 1 for each of the layers cause different colors. so i just gave an example of how you'd read it in and shoot it off to a colored image. If you run with it you'd see that all values 40 will be blue, 30's will be green and 20's be red.
baran
baran 2015년 3월 2일
Excuse me, you mean it produce a image with just 3 colors? if i want to produce a image with so many colors , what should i do ? thanks a lot
well what have you tried? you can work with colormaps to define colors like
IMG = raw;
IMG(isnan(IMG))=0;
numcolor = length(unique(IMG(:)));
colors = hsv(numcolor-1);
colors= [1 1 1;colors]; %set value of 0 to be white
imagesc(IMG)
colormap(colors)
what if the image is grayscale ? is the command still the same?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Shreya Shetty
Shreya Shetty 2019년 7월 26일

0 개 추천

Get RGB components from previous excel sheet, display them and retreive original image
[file,Path]=uigetfile('*.xlsx','Select excel file of image matrix '); file=fullfile(Path,file); red=xlsread(file, 'A1:GR200'); green=xlsread(file, 'A201:GR400'); blue=xlsread(file, 'A401:GR600'); figuresubplot(3,2,1); imshow(red,[]); imwrite(uint8(red),'red.jpg'); t1=imread('red.jpg'); title('red channel') subplot(3,2,2); imshow(green,[]); imwrite(uint8(green),'green.jpg'); t2=imread('green.jpg'); title('green channel') subplot(3,2,3); imshow(blue,[]); imwrite(uint8(blue),'blue.jpg'); title('blue channel') t3=imread('blue.jpg'); subplot(3,2,5); im=cat(3, t1, t2, t3); imshow(im) title('retreived image')

카테고리

태그

질문:

2015년 3월 2일

댓글:

2023년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by