필터 지우기
필터 지우기

What is the use of "maxidx = max(A(:))+1" in the below code ? How does it work? Any alternate syntax for the below function?

조회 수: 11 (최근 30일)
The question and code is given below :-
input: spine.tif from MATLAB
Read the indexed image with the associated colormap, show the colormap functions of all color channels with the corresponding color;
[A,map]=imread("spine.tif");
maxidx = max(A(:))+1;
figure()
hold on;
plot(map(1:maxidx,1),'r')
plot(map(1:maxidx,2),'g')
plot(map(1:maxidx,3),'b')
hold off
Can someone explain the use of "maxidx = max(A(:))+1;" in this code .
Like what did the above code do?
Is there any syntax to do the above function?

채택된 답변

Stephen23
Stephen23 2021년 11월 8일
편집: Stephen23 2021년 11월 8일
"Can someone explain the use of "maxidx = max(A(:))+1;" in this code"
The image file contains an indexed image, stored using integer indices:
class(imread("spine.tif"))
ans = 'uint8'
imfinfo("spine.tif")
ans = struct with fields:
Filename: '/MATLAB/toolbox/images/imdata/spine.tif' FileModDate: '14-Apr-2015 15:06:00' FileSize: 73166 Format: 'tif' FormatVersion: [] Width: 490 Height: 367 BitDepth: 8 ColorType: 'indexed' FormatSignature: [73 73 42 0] ByteOrder: 'little-endian' NewSubFileType: 0 BitsPerSample: 8 Compression: 'PackBits' PhotometricInterpretation: 'RGB Palette' StripOffsets: [8 289 4019 8116 12408 16005 19646 23350 26632 29577 31936 34376 36508 38024 39717 41397 43125 46361 50216 54920 60170 65751 67261] SamplesPerPixel: 1 RowsPerStrip: 16 StripByteCounts: [281 3730 4097 4292 3597 3641 3704 3282 2945 2359 2440 2132 1516 1693 1680 1728 3236 3855 4704 5250 5581 1510 120] XResolution: 72 YResolution: 72 ResolutionUnit: 'Inch' Colormap: [256×3 double] PlanarConfiguration: 'Chunky' TileWidth: [] TileLength: [] TileOffsets: [] TileByteCounts: [] Orientation: 1 FillOrder: 1 GrayResponseUnit: 0.0100 MaxSampleValue: 255 MinSampleValue: 0 Thresholding: 1 Offset: 71244 ImageDescription: ''
"Like what did the above code do?"
Converts the maximum index of a integer indexed image (i.e. zero-based) into a MATLAB index (i.e. one-based).
"Is there any syntax to do the above function?"
What function?
  댓글 수: 3
Stephen23
Stephen23 2021년 11월 9일
" Is there any other way or alternate solution to show the colormap functions of all color channels with the corresponding color"
[A,map] = imread("spine.tif");
mx = 1+max(A(:));
rgbplot(map(1:mx,:))
Compared against the original approach:
figure()
hold on;
plot(map(1:mx,1),'r')
plot(map(1:mx,2),'g')
plot(map(1:mx,3),'b')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by